Hello DevForum, I am working on a game similar to Club Iris that plays a selection of certain songs over and over again. For some reason, the first song plays fine, but after it ends the script won’t start another song. Can anyone help me figure out why?
local SoundIDS = {
2685636911;
5098298388;
2916513007;
866774692;
531158940;
3263711192;
4754657595;
4521908173;
131396974;
5069810459;
513188679;
}
local LastUpdatedSong = 0
local Delay = 2
local MusicPlaying = false
local MusicStepped
MusicStepped = RunService.Stepped:Connect(function()
if LastUpdatedSong + Delay < tick() and not MusicPlaying then
LastUpdatedSong = tick()
MusicPlaying = true
Music.SoundId = "rbxassetid://".. tostring(SoundIDS[Random.new():NextInteger(1, #SoundIDS)])
loadSound(Music)
Music:Play()
local MusicName = MarketplaceService:GetProductInfo(tonumber(Music.SoundId:sub(14)))
print("Currently Playing: " .. tostring(MusicName.Name))
print(Music.TimeLength)
Music.Ended:Wait()
MusicPlaying = false
print'Ended'
end
end)
--from developer hub
local function loadSound(sound)
-- Has the sound already loaded?
if not sound.IsLoaded then
-- if not, wait until it has been
sound.Loaded:Wait()
end
end
loadSound(Workspace.Sound)
local soundids = {
123,
456,
789,
}
local music = script.Parent
while true do
local rngid = soundids[math.random(1,#soundids)]
music.SoundId = "rbxassetid://"..rngid
music.TimePosition = 0
music:Play()
local musicname = game:GetService("MarketplaceService"):GetProductInfo(tonumber(rngid))
print("Currently Playing: " .. tostring(musicname.Name))
print(tostring(music.TimeLength))
music.Ended:Wait(2)
end