table.Random

hey guys i am having a problem, i am trying to make it so it randomly picks a song and then plays it.

It works, but it plays both the songs at the same time

[lua]local Winsounds = {“nyan.mp3”,“owned.mp3”}

for k,v in pairs(player.GetAll()) do
v:EmitSound(table.Random(Winsounds))
end
[/lua]

Halp

If you’re running it serverside and there’s more than one player you’re going to hear one of the sounds for each person.

[lua]local sound = table.Random( {“nyan.mp3”,“owned.mp3” } )

for k, v in pairs( player.GetAll() ) do

       v:EmitSound( sound )

end[/lua]

Is this what you meant?

No. He’s saying that if it is server side than it will Emit a sound for each player on the server.

So if there was 10 people on the server, there would be 10 sounds playing at once. It’s like 95% chance that both songs will play at once.

Do you want each player to hear the same sound? If not, then you’ll need to make it play the sounds clientside for each player, or you’ll get the effect described above.

[lua]
local Winsounds = {“nyan.mp3”,“owned.mp3”}
local sound = Winsounds[math.random(1, #Winsounds)]
*
for k, v in pairs(player.GetAll()) do
v:ConCommand("play " … sound)
end
[/lua]

I suppose this is what you want, make sure you send the files with resource.AddFile somewhere in your script.