local plr = game.Players.LocalPlayer
repeat wait(1) until plr.Character
local chr = plr.Character
chr.Humanoid.Died:Connect(function()
print("Character died")
plr.CharacterAdded:Wait()
print("Character respawned")
end)
This is the first code before editing
local plr = game.Players.LocalPlayer
repeat wait(1) until plr.Character
local chr = plr.Character
chr.Humanoid.Died:Connect(function()
print("Character died")
plr.CharacterAdded:Wait()
print("Character respawned")
chr = plr.Character
chr:WaitForChild("Humanoid")
end)
This is the code after editing
Seems to be working right, but when player died again, function is not working in both codes. How do I detect when humanoid died from a local script properly so this function can work forever? I need this script to be located in the player scripts, not character scripts.

6 comments
You might also want to call it from a remote event.
I dont think calling it from a remote event is not the best idea. Are you talking about starter character script or a server script?
Btw this code is working how do i accept it?
You select it as the solution :)
You click “Accept Answer” below my post.
I can only report you, there is no button "accept answer"