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

Music restarting everytime the player dies, how to fix it?


-- Variables
local main = script.Parent:WaitForChild("Main")
local sound = script.Parent:WaitForChild("Sound")
local songs = {5034180086,1112199032,4513732143,4606400466,621227155} -- Songs go in here (ID ONLY)
local progress = main:FindFirstChild("ProgressBar").Progress
local songName = main:FindFirstChild("SongName")

-- Main Script

while wait() do -- Repeats itself continuously
	sound:Stop() -- Stops the music
	progress.Size = UDim2.new(0,0,1,0) -- Resets the song's progressbar
	if not sound.IsPlaying then -- If the song has stopped
		local songChosen = songs[math.random(1,#songs)] -- Chooses a random sound
		local asset = game.MarketplaceService:GetProductInfo(songChosen) -- Gets the sound's info
		sound.SoundId = "rbxassetid://".. songChosen
		sound:Play()
		songName.Text = asset.Name -- Changes to text to the sound's name
		wait(1) -- Prevents errors
		progress:TweenSize(UDim2.new(1,0,1,0),'Out','Linear',(sound.TimeLength)-1) -- Moves progress bar
		wait((sound.TimeLength)-1) -- Waits sound's time -1
	end
end

5 comments

0

Can anyone edit my script ?

2

Where is your music parented to?

0

Starter Gui > MusicGui (ScreenGui) > MasterScript (LocalScript)

0

Put it in StarterCharacter

0

it's not working

1 answer

Try This: if doesn't work put in sever script service, I think the reason is you didn't put the player added function.

game.Players.PlayerAdded:Connect(function(plr)
	-- Variables
local main = script.Parent:WaitForChild("Main")
local sound = script.Parent:WaitForChild("Sound")
local songs = {5034180086,1112199032,4513732143,4606400466,621227155} -- Songs go in here (ID ONLY)
local progress = main:FindFirstChild("ProgressBar").Progress
local songName = main:FindFirstChild("SongName")

-- Main Script

while wait() do -- Repeats itself continuously
    sound:Stop() -- Stops the music
    progress.Size = UDim2.new(0,0,1,0) -- Resets the song's progressbar
    if not sound.IsPlaying then -- If the song has stopped
        local songChosen = songs[math.random(1,#songs)] -- Chooses a random sound
        local asset = game.MarketplaceService:GetProductInfo(songChosen) -- Gets the sound's info
        sound.SoundId = "rbxassetid://".. songChosen
        sound:Play()
        songName.Text = asset.Name -- Changes to text to the sound's name
        wait(1) -- Prevents errors
        progress:TweenSize(UDim2.new(1,0,1,0),'Out','Linear',(sound.TimeLength)-1) -- Moves progress bar
        wait((sound.TimeLength)-1) -- Waits sound's time -1
    end
end
end)

2 comments

0

I put this script in this properties it's work [Starter Gui > MusicGui (ScreenGui) > MasterScript (LocalScript)]

0

it's not working

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