Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to add shuffle to my music system?

Asked by 3 years ago

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

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago

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

0
Thank you tbh i wouldnt guess it on my own just starting with lua and programming overall mati11190111 5 — 3y
Ad

Answer this question