This is a server script:
game.Players.PlayerAdded:connect(function(player)
local died = false
repeat wait() until player.Character
local Humanoid = player.Character:WaitForChild("Humanoid")
Humanoid.Died:connect(function()
died = true -- If player died, change variable
end)
player.CharacterAdded:connect(function(character)
if died then -- If the player died then
print(player.Name .. " has been resurrected!")
died = false
else -- If the player didn't die then
print(player.Name .. " has been refreshed!")
end
end)
end)
It's meant to differentiate between when a player dies (respawns) and when a player reloads their character (refreshes) with :LoadCharacter (which is not dieing). However when a player dies it incorrectly reads "player has been refreshed" rather than "player has been respawned". How can I fix this?

3 comments
"player" wasn't defined in the second paragraph, so I moved the end for the playeradded event to the end of the second paragraph, and... IT STILL SAYS REFRESHED WHEN I DIE! This is infuriating!
No need to thumbs down.
Sorry, it's just that it's clear this hasn't been tested and it's just a total waste of time.