Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I fix this sound script?

Asked by
itsJooJoo 195
8 years ago

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!

0
I edited my answer. User#11440 120 — 8y
0
Ok itsJooJoo 195 — 8y
0
Why did you un-accept my answer? I answered your question didn't I :/ User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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!

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 itsJooJoo 195 — 8y
0
Well, this is because you're using two screens. In a real game, the players can't hear the other player's sounds. User#11440 120 — 8y
0
And if they can, it's because FE is disabled. It's always better to use FE. User#11440 120 — 8y
0
I used FE, and I heard it repeating when my friend from another city played. I could hear both of them. itsJooJoo 195 — 8y
View all comments (3 more)
0
I'm assuming you didn't use a local script then, and/or don't know what FE is. User#11440 120 — 8y
0
FE = FilteringEnabled. I used a LocalScript and put it in every possible client-sided folder there was itsJooJoo 195 — 8y
0
I'm not sure then, I'm sorry :/ User#11440 120 — 8y
Ad

Answer this question