Hi developers. I am trying to implement a queue into this music script.
I’ve been finding this difficult because I am not sure how to turn a queue table from { nil, 4330750213, 340951804, nil, 4977240932}
into { 4330750213, 340951804, 4977240932}
.
Is there a way to accomplish this using an array (queue), table.insert(queue, songId)
and table.remove()
?
song_ID = {4656290260, 1616059979, 5169111707, 4330750213, 4676627986, 340951804, 4977240932, 2852658307,
4900674369, 4900674369, 2619399246, 3612227852, 3612227852, 3612227852, 4097612623, 3444615787, 2852658307,
2832773762
}
asset_ID = "http://www.roblox.com/asset/?id="
function choose() local id = song_ID[math.random(1,#song_ID)] return id end
song = workspace.Music
if #song_ID > 0 then
while true do
song:Stop()
wait()
local songId = choose(song_ID)
song.SoundId = asset_ID..""..songId
local fol = game.ReplicatedStorage.SongInfo
fol.ID.Value = songId
wait(1)
if song.TimeLength ~= 0 then
song.TimePosition = 0
song:Play()
repeat
wait(1)
------[VOTING]------
local skip = false
local votes = 0
for _, plr in pairs(game.Players:GetChildren()) do
pcall(function()if plr.Voted.Value == true then votes = votes + 1 end end)
end
if votes >= (#game.Players:GetChildren()/2) then
skip = true
end
until song.TimePosition == 0 or skip
end
for _, plr in pairs(game.Players:GetChildren()) do
plr.Voted.Value= false
end
end
end
(Yes, I know there is room for improvement in this script. Please focus on the task given rather than correcting mistakes.)
Thanks a ton,
Winky.