Gui tween will only execute once

I have this gui tween play every time a player dies. But. it only works after the player has died once. I tried looking around the forum but I couldn’t find an exact solution.

I placed this local script in the StarterPlayerScripts because if I placed it in the SCS it will only work halfway through the tween since the character and the scripts inside of it reset on spawn.

The variables in the code snippet are all defined and there are no errors in the output. Any help would be greatly appreciated.

local function deathFade()
	deathFadeTween:Play()

	wait(1.5)

	whiteBar:TweenSize(UDim2.new(0.2, 0, 0, 2))
	wait(1)
	deathTextTween:Play()

	wait(3)

	deathTextTween1:Play()
	wait(1)
	whiteBar:TweenSize(UDim2.new(0, 0, 0, 2))	

	wait(1.5)

	deathFadeTween1:Play()
end

localHumanoid.Died:Connect(function()
	deathFade()
end)

Likely because the humanoid defined inside the localHumanoid no longer exists so I suggest you do plr.Character.Humanoid.Died rather.

2 Likes

Hm, I thought that would do the trick until it didn’t. I’ll look into the gui to see if anything is off there.

The humanoid no longer exists after the player died, so you have to assign to the variable again.

local localHumanoid
player.CharacterAdded:Connect(function(char)
   localHumanoid = char:WaitForChild("Humanoid")
end)
2 Likes

The humanoid variable is not nil anymore whenever a player respawns now, but I narrowed down the issue to the .Died event because it doesn’t want to fire after the player has died once.

local localHumanoid
player.CharacterAdded:Connect(function(char)
   localHumanoid = char:WaitForChild("Humanoid")

   localHumanoid.Died:Connect(function()
      deathfade()
   end)
end)
1 Like

The gui won’t tween anymore with this code

I finally find a working solution.It isn’t pretty but I’ll post the code.

I needed to connect two .died events. The bottom one is for when the player first dies, then the other one triggers after the player dies more than once. I do not know why it works, but it does.

localPlayer.CharacterAdded:Connect(function(character)
	localCharacter = character
	localHumanoid = localCharacter:WaitForChild("Humanoid")
	localHumanoid.Died:Connect(function()
		resetLighting()
		deathFade()
	end)	
end)

localHumanoid.Died:Connect(function()
	resetLighting()
	deathFade()
end)