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

Creating a Working Music Playlist?

Asked by 4 years ago
Edited 4 years ago

First of all a missive thank you for taking some time out of your life viewing this query. Without further delay, let's begin!

So I'm currently developing a game and I want to add a music playlist to it. I tried to this myself and it works fine in Studio, but after I published it and tested it out it got kinda bugged. So let me show you what I actually did.

https://drive.google.com/file/d/1-V4UcEan9PsujDYaemzjs-Zkd0PG3Q4o/view?usp=sharing

*If the link doesn't work, kindly copy and paste it into your browser.

So the above file shows all the things related to sound and music. You may also have noticed there is a script in there. The script is

while true do wait()
    script.Parent:WaitForChild("CoffinDance"):Play()
        wait(script.Parent:WaitForChild("CoffinDance").TimeLength)
    script.Parent:WaitForChild("DoubleBox"):Play()
        wait(script.Parent:WaitForChild("DoubleBox").TimeLength)
    script.Parent:WaitForChild("OkBoomer"):Play()
        wait(script.Parent:WaitForChild("OkBoomer").TimeLength)
    script.Parent:WaitForChild("RainingTacos"):Play()
        wait(script.Parent:WaitForChild("RainingTacos").TimeLength)
end

I just don't know why it's running fine in Studio, but messing up when I publish the game.

1 answer

Log in to vote
1
Answered by
Sparks 534 Moderation Voter
4 years ago

I am not sure what "bugged" means, if you could comment with what exactly is bugged that would be helpful. Nevertheless, there is a .Ended event for Sound instances you can use rather than waiting for the timelength. You should also future-proof your code in case you add extra Sounds in the future.

while true do wait()
    --Get all children of playlist folder
    for i,v in pairs(script.Parent:GetChildren()) do 
        --Make sure object is a Sound
        if v:IsA("Sound") then
            --Play sound
            v:Play() 
            --Wait for .Ended event to fire (song ended)
            v.Ended:Wait() 
            --Continue to next sound
        end
    end
end

0
Thanks man! You are a true lifesaver. :) XLeMysterioX 22 — 4y
Ad

Answer this question