I'm making this song system for my game and i made a gui that randomly selects one of the songs in the folders in the gui, so how would i play the selected song?
-- The songs are in the folder which the script in the gui selects.
-- Script in the gui
local Player = game.Players.LocalPlayer Songs = script["Music"]:GetChildren() Selected = nil MTL = .25 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- function Song() Random = Songs[math.random(1,#Songs)] Selected = Random script.Parent.Playing.Playing.Text = Selected.Name wait() for i = 1,#Selected:GetChildren(),1 do Selected:GetChildren()[i]:Play() wait(Selected:GetChildren()[i].Duration.Value-MTL) end end while true do Song() end Player.Character.Humanoid.Died:connect(function() for Index,A in pairs(Selected:GetChildren()) do if A:IsA("Sound") then A:stop() end end end)
Here is what I would do:
while true do local songs = {script.Music.MarshmallowAlone,It'sRainingTacos} -- put your song names in there local chosen = songs[math.random(1,#songs)] chosen:Play() repeat end
Be aware I am new to scripting so this may not work.
If this helped please accept this answer.
In line 17, instead using normal wait() function (which is use to wait for a number of time), we can do like this:
Selected:GetChildren()[i].Ended:Wait()
This will cause the script wait until the song end and continue.
*This is the first time I answer someone is question. If there is any issue, don't harm me :)