Here is the code that runs my music player GUI:

local ids = {621227155,752822169,366682733,2791840337,2256815493,4809353556,2999098267,4612709834,1096171165}


local music = script.Parent:WaitForChild("Music")
local titlelabel = script.Parent:WaitForChild("SongTitle")
local uploaderlabel = script.Parent:WaitForChild("Uploader")
local albumcover = script.Parent:WaitForChild("AlbumCover"):WaitForChild("UploaderImage")
local timelabel = script.Parent:WaitForChild("Time")
local timefill = script.Parent:WaitForChild("FillFrame"):WaitForChild("Fill")

while wait() do
	local currentsong = ids[math.random(#ids)]
	music.SoundId = "rbxassetid://"..currentsong
	titlelabel.Text = "Song: "..game:GetService("MarketplaceService"):GetProductInfo(currentsong).Name
	uploaderlabel.Text = "Uploaded by: "..game:GetService("MarketplaceService"):GetProductInfo(currentsong).Creator["Name"]
	albumcover.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username="..game:GetService("MarketplaceService"):GetProductInfo(currentsong).Creator["Name"]
	wait()
	timefill.Size = UDim2.new(0,0,1,0)
	music:Play()
	wait(0.5)
	timefill:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, math.ceil(music.TimeLength - 0.5))
	wait(0.5)
	wait(math.ceil(music.TimeLength - 0.5))
	music:Stop()
end

Although I still want the music to be random, I find that despite there being many song IDs, the same song often gets chosen two, or even 3 times in a row. Any tips on what code to add to prevent this from happening? I want the music to be as different as possible. Thanks!

1 comment

0

You could try just using two tables, and table 1 being the list of songs and table 2 being used to store sounds when the Sound.Ended event fires.