I have a game I'm working on and am trying to make it so upon death, the sound is random. Here's what I have so far:
function Died(p) wait(.001) local tracks=game.ServerStorage:GetChildren() local rn=math.random(1,#tracks) local track=tracks[rn] track:Play()
Anyone have any idea as to why it's not working? It's a local script in the workspace.
Your code is attempting to play a sound that is a child of ServerStorage. This will not work. You should move the sound into Workspace (for global sound) or, into the character of the player who has died (local sound)
local SoundAmount = 0 local Sounds = {} function Died(p) SoundAmount = 0 Sounds - {} for _, e in pairs([path of sounds]:GetChildren() do SoundAmount = SoundAmount + 1 table.Insert(Sounds, e) end local SoundChoice = math.random(1, SoundAmount) for i, e in ipairs(Sounds) do if SoundChoice == i then [path of sounds][e]:Play() end end end)
As far as im concerned this should work. You might need to do some testing and debugging.