Hi there, I have a music playlist script which goes through a table and randomly plays a song one at a time. The issue is, is that when the a song ends and goes through the next song to play, there’s a chance that the math.random could go to the same value and play that same song again. I don’t have an attempt as I am unsure on what to do.
local MPS = game:GetService("MarketplaceService")
local currentTrack = game.ReplicatedStorage.CurrentTrack
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound
local id = game.ReplicatedStorage.songid
music = {
"rbxassetid://3044286747",
"rbxassetid://1256391355",
"rbxassetid://5480102561",
"rbxassetid://5024527209",
"rbxassetid://870242868",
"rbxassetid://1112109949",
"rbxassetid://6303331764",
"rbxassetid://2206587324",
"rbxassetid://5987864893",
"rbxassetid://534429024",
"rbxassetid://4551177864",
"rbxassetid://664277618",
"rbxassetid://3011342543",
"rbxassetid://3523361267",
"rbxassetid://3616424949";
}
while true do
if not musicplayer.IsPlaying then
local RandomSong = music[math.random(1, #music)]
local SongID = string.match(RandomSong, "%d+")
local SongInfo = MPS:GetProductInfo(SongID)
musicplayer.SoundId = RandomSong
musicplayer:Play()
currentTrack.Value = "..." -- displays the song playing in a music player gui
currentTrack.Value = SongInfo.Name -- just for displaying current song playing
musicplayer.Ended:Wait()
game:GetService("RunService"):UnbindFromRenderStep("CurrentTrack")
end
end