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

how do i make a script that plays through different music?

after one music finishes, another music plays but this script does not work for some reason

local sound1 = 561833161 -- lchavasse - lunar abyss
local sound2 = 853077574 -- creo - sphere
local sound3 = 251954030 -- the final phase
local sound4 = 227436821 -- f777 - invincibility star
local sound5 = 657629765 -- waterflame - arcade punk
local music = script.Parent

while true do
	music.SoundId = "rbxassetid://"..sound1
	music:Play()
	print("music 1 is playing")
	wait(232)
	music.SoundId = "rbxassetid://"..sound2
	music:Play()
	print("music 2 is playing")
	wait(242)
	music.SoundId = "rbxassetid://"..sound3
	music:Play()
	wait(122)
	music.SoundId = "rbxassetid://"..sound4
	music:Play()
	wait(96)
	music.SoundId = "rbxassetid://"..sound5
	music:Play()
	wait(242)
end

also, is there a more efficient way than just working out the wait time?

1 comment

0

If you have the file for the sound asset and you use a software you may be able to find out the exact wait time, if you don't then contact me on discord for more help - StandingMcdonalds#8924

2 answers

✓ Accepted answer

Ensure your Sound Instance is within workspace, as these Objects can only be heard in physical environments. Since workspace is a global container, this Script cannot be Local.

local SoundIds = {
    ["Ichavasse - Lunar Abyss"] = 561833161;
    ["Creo - Sphere"] = 853077574;
    ["The Final Phase"] = 251954030;
    ["F777 - Invincibility Star"] = 227436821;
    ["Waterflame - Arcade Punk"] = 657629765;
    ["Tristam - Till It's Over"] = 147632111; --// Thought you'd like this
}

local SoundObject = script.Parent

local function TraverseSongsFrom(SongList)
    if not (SongList) then return end
    for Title,Id in next, SongList do
        SoundObject.SoundId = "rbxassetid://"..tonumber(Id)
        repeat wait() until SoundObject.IsLoaded
        SoundObject:Play()
        SoundObject.Ended:Wait()
        SoundObject:Stop()
    end
end

while wait() do TraverseSongsFrom(SoundIds) end

If you wish, you can optionally write print(Title.." Is now playing!"), or you can revert to an array of just IDs and use this line instead:

local MpS = game:GetService("MarketplaceService")
print(Mps:GetProductInfo(Id).Name.." Is now playing!")

Here you can add more songs in the first two lines

local sound1 = 000000000-- Sound IDs
local sound2 = 000000000
local music = script.Parent
 
function Song() -- Creating the random function
    local song = math.random(1,2) -- change the 2 for the max songs you have 
    if song == 1 then
        music.SoundId = "rbxassetid://"..sound1
    else if song == 2 then
        music.SoundId = "rbxassetid://"..sound2
        end
    end
end
 
while true do -- Loop
    wait()
    Song() -- Calling the function (Choosing the song at random)
    wait(.1)
    music:Play() -- playing the random song chosen
    music.Ended: wait() 
end
 

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