You might be confused with "How do I play multiple sounds at once in my game?". What I mean is how do I make a sound after a sound after a sound. Like a soundtrack. This might be wrong but I need help.
while true do script.Parent:Play() wait(61) script.Parent:Stop() wait(1) end
First, make 2 sounds. Name then s1
and s2
Both must be in Workspace
.
then, make a script into Workspace and type this script into it:
while true do local s = {Workspace.s1, Workspace.s2} -- You can add more, if you add the 2nd sound name it `s3` and put it in that bar above. If it 4th one add name it s4 and put it in that, and put s3 in it. local i = math.random(1, #s) s[i]:Play() wait(61) s[i]:Stop() end
To do that you will use the property, IsPlaying
, to see if a sound is playing instead of using wait. I wrote this script which uses a table to store the sounds to play. Insert other sounds you want to play into the, sounds
, table. Don't forget to preload the sounds. Here it is:
sounds = {script.Parent} -- Add other sounds you want to play currentSound = nil -- Do not edit. key = 0 -- Do not edit. while wait() do if(currentSound == nil) then key = 1 currentSound = sounds[key] currentSound:Play() elseif(currentSound.IsPlaying == true) then wait(5) elseif(currentSound.IsPlaying == false) then if(key ~= #sounds) then key = key + 1 currentSound = sounds[key] else key = 1 currentSound = sounds[key] currentSound:Play() end end end
With the current Sound implementation on ROBLOX, we are lacking a system which lets us accurately determine if a sound is playing (or get its length). To create a soundtrack right now, you must use ContentProvider.Preload to load your sounds, and then make a note of the length of every track. Then you need to play the sound, wait the appropriate length, and then stop the sound, and play the next one.
Something like this:
local SoundObject = Workspace.Part.Sound local Sounds = { {id=1234, length=50}, -- asset ID, length in seconds {id=5678, length=20} } while true do for _, sound in ipairs(Sounds) do SoundObject:Stop() SoundObject.SoundId = "rbxassetid://" .. sound.id SoundObject:Play() wait(sound.length + 2) end end