Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I fix this sound script?

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!

3 comments

0

I edited my answer.

0

Ok

0

Why did you un-accept my answer? I answered your question didn't I :/

1 answer

I would recommend using a Local Script to fix your problem.

There might be a problem with the script's ability to read the sound's TimeLength property. To fix this, use a local script.


"But where would I put the 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.


"But what would I have to change?"

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.


"Will it be hard?"

Nah.


  • First,

Change the script into a Local Script and put it into StarterPack.

-- 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

  • Second,

Now we have access to some sound properties that would otherwise be unobtainable. We'll be waiting for the event 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

  • Finally,

You have to wait for OST to load using WaitForChild, like so,

-- 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!

7 comments

0

Ok well now it's playing, but when a new player joins, the song is duplicated and overlaps with the other person's sound. So there are a bunch of repeats as if this is row row row your boat or something

0

Well, this is because you're using two screens. In a real game, the players can't hear the other player's sounds.

0

And if they can, it's because FE is disabled. It's always better to use FE.

0

I used FE, and I heard it repeating when my friend from another city played. I could hear both of them.

0

I'm assuming you didn't use a local script then, and/or don't know what FE is.

0

FE = FilteringEnabled. I used a LocalScript and put it in every possible client-sided folder there was

0

I'm not sure then, I'm sorry :/

This discussion is preserved as it was. New answers, comments, and votes are closed.