I want to know how I make a song play after one ends so I can make a soundtrack for my game. Danke in advance ^-^ Oh, and is it possible to have multiple different soundtracks that I can play at different times via a GUI?
COMMUNITY QUESTION
How do I make another song play after one ends?
1 answer
As wfvj014 said in his comment, you can utilize the Ended event that's a member of the Sound object.
However, I'd also like to add the very clean addition of using the wait method on the event signal, so your script will yield whatever happens after the song has ended. Here would be an example of playing each song from a table in order, only after the previous one has finished:
This will require you to have prior knowledge of tables, for loops, and functions.
-- Get the local player
local Player = game:GetService("Players").LocalPlayer
-- Parent the sound object to the local player's PlayerGui
local Sound = Instance.new("Sound",Player:WaitForChild("PlayerGui"))
-- Array of song Ids
local Songs = {
"190454307",
"155968128",
"338928272",
}
-- Create a function for this process
local function PlaySongsInOrder()
-- Main loop
for i = 1,#Songs do
-- Song Id
local s = Songs[i]
-- Set the sound id
Sound.SoundId = "rbxassetid://"..s
-- Play the sound
Sound:Play()
-- Don't carry on until the current song has ended
-- (this is why the wait method on event signals
-- is so freaking awesome and useful)
Sound.Ended:wait()
-- End the for loop
end
-- End the function
end
-- Initiate
PlaySongsInOrder()
If you have any questions, just let me know.
2 comments
0
You spelt my name right. Thank you.
0
Danke so much, this was so helpful! <3
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
There is a song.Ended event but it's only accessible in a local script.