Jump to content

random playsound


Recommended Posts

client side

function endVol()
    local position = guiScrollBarGetScrollPosition(Cock2)/100	
	local Number = math.random(1,37)
    muzik = playSound("sounds/"..tostring(Number)..".mp3")
    setSoundVolume(muzik, position)
end
addEvent("endvol",true)
addEventHandler("endvol", getRootElement(), endVol)


server side

function muzikS( )
	triggerClientEvent( source,"endvol", source )
end
addEventHandler( "onRoundFinish", root, muzikS )

im trying to get the same random song to play on all clients
this plays different per client

Link to post

Hey,

Generate the random number from the server side and pass it to all the clients through the triggerClientEvent.
This way everyone will hear the same sound.

Link to post
3 minutes ago, SpecT said:

Hey,

Generate the random number from the server side and pass it to all the clients through the triggerClientEvent.
This way everyone will hear the same sound.

im not sure how to do this xD i knew i had to use random.math on server but idk how to pass it

Link to post
1 minute ago, greentumbleweed said:

im not sure how to do this xD i knew i had to use random.math on server but idk how to pass it

Client side:

function endVol(soundNum)
	local position = guiScrollBarGetScrollPosition(Cock2)/100	
	muzik = playSound("sounds/"..tostring(soundNum)..".mp3")
	setSoundVolume(muzik, position)
end
addEvent("endvol",true)
addEventHandler("endvol", root, endVol)

Server side:

function muzikS()
	local soundNum = math.random(1,37)
	triggerClientEvent( root,"endvol", resourceRoot, soundNum )
end
addEventHandler( "onRoundFinish", root, muzikS )

It will be helpful to you to read the documentation for the function triggerClientEvent so you will know what argument is for what in future uses. 🙂

Link to post
31 minutes ago, SpecT said:

Client side:


function endVol(soundNum)
	local position = guiScrollBarGetScrollPosition(Cock2)/100	
	muzik = playSound("sounds/"..tostring(soundNum)..".mp3")
	setSoundVolume(muzik, position)
end
addEvent("endvol",true)
addEventHandler("endvol", root, endVol)

Server side:


function muzikS()
	local soundNum = math.random(1,37)
	triggerClientEvent( root,"endvol", resourceRoot, soundNum )
end
addEventHandler( "onRoundFinish", root, muzikS )

It will be helpful to you to read the documentation for the function triggerClientEvent so you will know what argument is for what in future uses. 🙂

i read the page for triggerClientEvent and seen the argument but i didnt realize you can just use a variable for that there xD thanks a lot

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...