For some reason, I made this radio to globally play songs and loop, but it plays the first song then ends. I have absolutely no clue why its doing this. (I've already tried replacing Ended with Stopped, it came to no avail.) It gives no error in the console. I can't find out any working way to make it switch.
local id1 = "rbxassetid://215717985" local id2 = "rbxassetid://193424165" local id3 = "rbxassetid://263562509" local id4 = "rbxassetid://466347974" local id5 = "rbxassetid://512934146" mori = game.Workspace.MORIOHRADIO game.Workspace.MORIOHRADIO.SoundId = id1 mori:Play() mori.Ended:Connect(function() if game.Workspace.MORIOHRADIO.SoundId == id1 then mori.SoundId = id2 mori:Play() end if game.Workspace.MORIOHRADIO.SoundId == id2 then mori.SoundId = id3 mori:Play() end if mori.SoundId == id3 then mori.SoundId = id4 mori:Play() end if mori.SoundId == id4 then mori.SoundId = id5 mori:Play() end if mori.SoundId == id5 then mori.SoundId = id1 mori:Play() end end)
All 5 if statements are executing and playing the sound!
If you used elseif, you would fix the problem, as the other bodies don't get executed if one of the conditions is already truthy:
local id1 = "rbxassetid://215717985" local id2 = "rbxassetid://193424165" local id3 = "rbxassetid://263562509" local id4 = "rbxassetid://466347974" local id5 = "rbxassetid://512934146" mori = game.Workspace.MORIOHRADIO game.Workspace.MORIOHRADIO.SoundId = id1 mori:Play() mori.Ended:Connect(function() if game.Workspace.MORIOHRADIO.SoundId == id1 then mori.SoundId = id2 mori:Play() elseif game.Workspace.MORIOHRADIO.SoundId == id2 then mori.SoundId = id3 mori:Play() elseif mori.SoundId == id3 then mori.SoundId = id4 mori:Play() elseif mori.SoundId == id4 then mori.SoundId = id5 mori:Play() elseif mori.SoundId == id5 then mori.SoundId = id1 mori:Play() end end)
But this code is still messy!
What you should do is have a table that contains all the IDs, traverse it, and assign the SoundId
to each ID in the table.
Like so:
local soundIds = { "rbxassetid://215717985", "rbxassetid://193424165", "rbxassetid://263562509", "rbxassetid://466347974", "rbxassetid://512934146" } local mori = game.Workspace.MORIOHRADIO while true do for _, soundId in ipairs(soundIds) do mori.SoundId = soundId mori:Play() mori.Ended:Wait() end end
Here's what happens:
soundIds
SoundId
to whatever soundId
is