local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local RS = game:GetService("ReplicatedStorage")
local died = RS.Died
humanoid.Died:Connect(function()
died:FireServer()
end)
The humanoid is always defined correctly, I tested it with printing. How come it can only detect the player die once?
Your character reference becomes nil and disconnects your Died connection when the character disappears after the timeout in Players.RespawnTime. Fix it by defining the connection in a variable and re-connecting it everytime the character gets added:
local function DiedEvent()
died:FireServer()
end
local HumanoidDied = humanoid.Died:Connect(DiedEvent)
Player.CharacterAdded:Connect(function(NewCharacter)
character = NewCharacter
HumanoidDied = humanoid.Died:Connect(DiedEvent)
end)
My script is in a local script and I’m only trying to detect when the local player dies. Also I don’t do custom local functions when it’s unnecessary, they confuse me and this script is hard to read for me.
How are custom local functions confusing? They’re the same as normal functions.
Also the script isn’t too hard to read unless you took the code you provided in your post from somewhere else.