Death effect works once and never again

local script inside a screengui in startergui

--makes black screen appear when player dies and shortly after fade away

game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

local tweenServ = game:GetService("TweenService")
local humanoid = game.Players.LocalPlayer.Character.Humanoid

humanoid.Died:Connect(function()
	script.Parent.Enabled = true
	wait(3)
	local uiTween = tweenServ:Create(script.Parent.Frame, TweenInfo.new(3, Enum.EasingStyle.Linear), {BackgroundTransparency = 1})
	uiTween:Play()
	uiTween.Completed:Wait()
	script.Parent.Enabled = false
	script.Parent.Frame.BackgroundTransparency = 0 --reset back to visible
	
end)

works once and never again
in fact i checked and i dont even think the “died” event is firing
why is this?

2 Likes

its because you are setting the script to disabled so it cant even check if the character died.

when did i do that
ive set the screengui to disabled some times but i dont see where i disabled the script

script.Parent.Enabled = false here in the script after the tween ends

1 Like

…?
yeah
thats
script.Parent is the screengui im disabling the screengui not the script…?

Is this script inside a ScreenGui? If so then turn on “ResetOnSpawn” property of the ScreenGui so it can run the script again after you respawn.

1 Like

Once the ScreenGui is disabled, the script won’t load after a respawn.

1 Like

Oh im sorry my bad i thought you were disabling the script lol

1 Like

ok that works
but
i have the “reset on spawn” turned off so that it doesnt reset the ui when you die, considering i wont it to still be black when you respawn and fade away after a few seconds

Then you should be using a CharacterAdded event so that you can connect the .Died event to the new Humanoid instance because every time your character dies your character model changes and connection disconnects after it’s destroyed. So what you can do is something like this:

game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

local player = game.Players.LocalPlayer

local tweenServ = game:GetService("TweenService")
local humanoid = player.Character.Humanoid

local connection

local function died()
	connection = nil
	script.Parent.Enabled = true
	wait(3)
	local uiTween = tweenServ:Create(script.Parent.Frame, TweenInfo.new(3, Enum.EasingStyle.Linear), {BackgroundTransparency = 1})
	uiTween:Play()
	uiTween.Completed:Wait()
	script.Parent.Enabled = false
	script.Parent.Frame.BackgroundTransparency = 0
end

connection = humanoid.Died:Connect(died)

player.CharacterAdded:Connect(function(char)
	local human = char:WaitForChild("Humanoid")
	connection = human.Died:Connect(died)
end)
3 Likes

Instead of doing just add a separate function on CharacterAdded (respawns) that sets everything back to where it was.

1 Like