Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add shuffle to my music system?

So i made music system for my obby game but i need it to shuffle songs and i dont know how to do it since im am pretty much newbie in scripting help? here is the script:

local MarketPlaceService = game:GetService("MarketplaceService")

local Songs = { 5410082097, 4324837704, 3357763594

}

local SongObject = script.Parent.Song local SongLabel = script.Parent.SongLabel local SkipButton = script.Parent.SkipButton local MuteButton = script.Parent.MuteButton

MuteButton.MouseButton1Click:Connect(function() if SongObject.Volume == 0.25 then SongObject.Volume = 0 else SongObject.Volume = 0.25 end end)

SkipButton.MouseButton1Click:Connect(function() SongObject:Stop() end)

while true do for i = 1, #Songs do local Song = Songs[i] local SongInfo = MarketPlaceService:GetProductInfo(Song)

	SongObject.SoundId = "rbxassetid://" .. Song
	SongObject:Play()
	SongLabel.Visible = true
	SongLabel.Text = SongInfo.Name
	
	repeat wait() until not SongObject.IsPlaying
end

end

1 answer

instead of local Song = Songs[i], do local Song = Songs[math.random(1,#Songs)]

1 comment

0

Thank you tbh i wouldnt guess it on my own just starting with lua and programming overall

This discussion is preserved as it was. New answers, comments, and votes are closed.