Sound resets after death

I have this music menager and can i somehow do it so the sound will continue even when player will die, because now it resets and plays from the beggining. (Its a local script)


local Songs = {
--ID's in here
}

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

MuteButton.MouseButton1Click:Connect(function()
	if SongObject.Volume == 0.5 then
		SongObject.Volume = 0
	else
		SongObject.Volume = 0.5
	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
		wait(3)
		SongLabel.Visible = false

		repeat wait() until not SongObject.IsPlaying
	end
end

Im guessing this script is inside StarterGui, if it is set your Gui’s ResetOnSpawn property to false then it should work.

1 Like

The music restarts anyway, any other idea?

i think i know how to fix this give me some minutes

ok i got this you should insert the song into player(not character) and it will continue playing
should work

So it’ll be like this?

local player = game.Players.LocalPlayer
local SoundObject = script.Song


player.PlayerAdded:connect(funcion()
local SoundCopy = SoundObject:Clone()
SoundCopy.Parent = player
end

i think so you can try it i wanna see if it actually gona work because for me it worked well

You could just reference the Player’s GUI itself in StarterPlayerScripts , I believe scripts inside StarterGui would still restart regardless even if the ResetOnSpawn property is set to false (Not sure though)

--LocalScript inside StarterPlayerScripts

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Songs = {
--ID's in here
}
 --Change these to where your object is inside the Gui
local SongObject =
local SongLabel = 
local SkipButton = 
local MuteButton =

MuteButton.MouseButton1Click:Connect(function()
	if SongObject.Volume == 0.5 then
		SongObject.Volume = 0
	else
		SongObject.Volume = 0.5
	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
		wait(3)
		SongLabel.Visible = false

		repeat wait() until not SongObject.IsPlaying
	end
end
1 Like

Music plays, but you can’t mute, skip or the song name isn’t displaying

Did you reference your variables correctly?

I think so
image

local SongObject = game.StarterGui.BtnsGui.Frame.Song
local SongLabel = game.StarterGui.BtnsGui.SongLabel
local SkipButton = game.StarterGui.BtnsGui.Frame.SkipButton
local MuteButton = game.StarterGui.BtnsGui.Frame.MuteButton
  if humanoid.died = True then
     song.playing = False
wait(5)-----------------------YOU CAN PUT ANY TIME---- 
 song.playing = true

sry i have to do the wobbly
Hopefuly it works!!!

That’s not the right way

The StarterGui is replicated across the server-side, which the client will not detect its changes on

You have to reference the PlayerGui in the example I gave, put the LocalScript inside StarterPlayerScripts and try this:

--LocalScript inside StarterPlayerScripts

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Songs = {
--ID's in here
}

local GuiObject = PlayerGui:WaitForChild("BtnsGui")
local SongObject = GuiObject:WaitForChild("Frame").Song
local SongLabel = GuiObject:WaitForChild("SongLabel")
local SkipButton = GuiObject:WaitForChild("Frame").SkipButton
local MuteButton = GuiObject:WaitForChild("Frame").MuteButton

MuteButton.MouseButton1Click:Connect(function()
	if SongObject.Volume == 0.5 then
		SongObject.Volume = 0
	else
		SongObject.Volume = 0.5
	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
		wait(3)
		SongLabel.Visible = false

		repeat wait() until not SongObject.IsPlaying
	end
end

The buttons and everything works, but when you die its not only resetting the sound, but it stops it, the songlabel has the placeholder text and the buttons don’t work

How though

Try sending a reproduction file? I don’t exactly see anything that could be resetting the song, unless if you change SongObject:Play() to SongObject:Resume()

Another thing, but you could change this

		repeat wait() until not SongObject.IsPlaying

To this

SoundObject.Ended:Wait()

A bit more reliable