So I used a ServerScript inside workspace, and in it I added a model named OST. Inside OST, I put various sounds (more like popular songs) inside it. In the ServerScript, I put thisFindFirstChild line of code:
songs = {'DeathOfABachelor', 'DontThreatenMeWithAGoodTime', 'Focus', 'IntoYou', 'MrsPotatoHead', 'MyHouse', 'No', 'PityParty', 'Radioactive', 'WorkFromHome', 'iWriteSinsNotTragedies', 'Work', 'StressedOut'} --Lol this is a lot of songs :P for i=1,#songs do local sound = script.OST:findFirstChild(songs[i]) sound:Play() wait(sound.TimeLength) end
So what's the problem? In Studio, it works just fine. However, in the game, it plays all of the songs at once. In the "wait(sound.TimeLength)" part, I made it specifically so that NOT all the songs will play at the same time. Please help!
There might be a problem with the script's ability to read the sound's TimeLength
property. To fix this, use a local script
.
I would suggest putting the Local Script
in StarterPack
. You could also put it in StarterGui
or even ReplicatedFirst
. However, StarterPack
will be the one I use in my example.
Not much actually. You would have to move the script to StarterPack
, and change the script into a Local Script, along with a few other changes.
Nah.
-- LocalScript in StarterPack local songs = {'DeathOfABachelor', 'DontThreatenMeWithAGoodTime', 'Focus', 'IntoYou', 'MrsPotatoHead', 'MyHouse', 'No', 'PityParty', 'Radioactive', 'WorkFromHome', 'iWriteSinsNotTragedies', 'Work', 'StressedOut'} --Lol this is a lot of songs :P for i=1,#songs do local sound = script.OST:findFirstChild(songs[i]) sound:Play() wait(sound.TimeLength) end
Ended
to fire from the sound in place of line 7 in the script above.-- LocalScript in StarterPack local songs = {'DeathOfABachelor', 'DontThreatenMeWithAGoodTime', 'Focus', 'IntoYou', 'MrsPotatoHead', 'MyHouse', 'No', 'PityParty', 'Radioactive', 'WorkFromHome', 'iWriteSinsNotTragedies', 'Work', 'StressedOut'} --Lol this is a lot of songs :P for i=1,#songs do local sound = script.OST:findFirstChild(songs[i]) sound:Play() sound.Ended:wait() end
-- LocalScript in StarterPack local songs = {'DeathOfABachelor', 'DontThreatenMeWithAGoodTime', 'Focus', 'IntoYou', 'MrsPotatoHead', 'MyHouse', 'No', 'PityParty', 'Radioactive', 'WorkFromHome', 'iWriteSinsNotTragedies', 'Work', 'StressedOut'} --Lol this is a lot of songs :P for i=1,#songs do local sound = script:WaitForChild("OST"):FindFirstChild(songs[i])-- Wait For OST to load sound:Play() sound.Ended:wait() end
I hope I helped. If I did, remember to accept my answer. It helps a lot!
Good Luck!