I'm trying to make this script play random music each time, But It Won't Work any Suggestions or ideas? What did I do wrong?
X = (math.random(1,5))
function onPlayerAdded(newPlayer)
if X == 1 then
script.Parent.menu_sfx_audio.SoundId = "http://www.roblox.com/asset/?id=199768665"
wait(.5)
script.Parent.menu_sfx_audio:Play()
elseif X == 2 then
script.Parent.menu_sfx_audio.SoundId = "http://www.roblox.com/asset/?id=199768665"
wait(.5)
script.Parent.menu_sfx_audio:Play()
elseif X == 3 then
script.Parent.menu_sfx_audio.SoundId = "http://www.roblox.com/asset/?id=199768665"
wait(.5)
script.Parent.menu_sfx_audio:Play()
elseif X == 4 then
script.Parent.menu_sfx_audio.SoundId = "http://www.roblox.com/asset/?id=167135038"
wait(.5)
script.Parent.menu_sfx_audio:Play()
elseif X == 5 then
script.Parent.menu_sfx_audio.SoundId = "http://www.roblox.com/asset/?id=185601181"
wait(.5)
script.Parent.menu_sfx_audio:Play()
end
game.Players.PlayerAdded:connect(onPlayerAdded)

3 comments
line 1 should be switched with line two so that it is in the function
I would also put in; math.randomseed(tick()) to make stuff more random ;D
Can you provide a list of the full hierarchy please?