Player has a event called CharacterAdded.
Use this:
local Player = game:GetService("Players").LocalPlayer
game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function()
Player.Character:WaitForChild("Humanoid").Died:Connect(function()
print("Humanoid died!")
end)
end)
Also, Humanoids, and pretty much characters, get destroyed whenever they die, so if you need to constantly check if a player dies, the function above will guarantee that. Most use CharacterAdded:Wait() which only runs once, but functions run until disconnected.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
print("Died.")
end)
Local scripts inside of StarterCharacterScripts are cloned into the player’s character each time it spawns/reloads (is added).
If you were hellbent on having this script inside of StarterPlayerScripts then you could do the following.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
print("Died.")
end)
end)
I don’t know if one of us is misunderstanding the other, but what I mean is that a :Wait function yields and only works once. Once a player dies, their character is destroyed and replaced with the StarterPlayer model (Or the default). This is to remove unneeded parts, scripts, etc, so, since CharacterAdded only works once, it doesn’t know if it happens again unless it is connected to a function and repeatedly resets the Humanoid.Died function (The previous one will be disconnected automatically because that’s what ROBLOX does)