--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?
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)