Edit: The script wasn't registering soundInstance.TimeLength, so I had to force it to yield until said property was greater than 0. Now it works just fine!
What I'm trying to make here is a script that starts playing music upon the server starting up.
My problem is that while true do seems not to behave properly when starting a solo playtest in Roblox Studio. Here's the full code:
local playlist = {
"5834656055",
"3124464124",
"5217321559"
}
local soundInstance = workspace:FindFirstChild("Music") do
if not soundInstance then
soundInstance = Instance.new("Sound", workspace)
soundInstance.Name = "Music"
end
end
while true do
for _, v in pairs(playlist) do
if typeof(v) ~= "string" then
continue
end
print(v)
soundInstance.SoundId = "rbxassetid://" .. v
soundInstance:Play()
wait(soundInstance.TimeLength)
end
end
Instead of the intended behavior, the script seems to either skip the first element of playlist and play half of the second element, then skip to the third one or play the first element of playlist, skip the second one and play the third. And yes, I've tested the integrity of each audio ID.
Why does this happen? Is there any workaround to this? I'm not new to Lua, but I've never had this happen before.

2 comments
Debounce although that probab;y wouldn't work, and try doing a while wait() loop
Forgot to update this: the script wasn't registering the length of the sound, so I had to force it to yield until soundInstance.TimeLength was greater than 0.