I am attempting to create a music system that just simply plays random sound ID from a list of music provided by a table.
-- all server-side
local soundInstance = Instance.new("Sound", workspace) -- I only parent so don't kill me for using second argument
local function playSong()
local newSong = getRandomSong()
soundInstance.SoundId = "rbxassetid://"..newSong.Id
if not soundInstance.IsLoaded then
soundInstance.Loaded:Wait()
end
print("Loaded "..newSong.Name)
soundInstance:Play()
print("Song "..newSong.Name.." now playing..")
end
coroutine.wrap(function()
local players = game.Players
while true do
if #players:GetPlayers() == 0 then
players.PlayerAdded:Wait()
end
playSong()
soundInstance.Ended:Wait()
end
end)()
I am having the sound randomly pause when it ends (doesn’t even fire Paused
event) and sometimes a new song plays before the current ends then goes halfway in. getRandomSong()
just gets a random sound ID so not really anything new to have by showing it.
This bug is consistent in ingame testing and Studio testing.
Test File used:
SongTest.rbxl (18.5 KB)