Get current player state (death-detection)

Hello recently I needed to detect when a player is dead or alive.
This comes handy with a if statement I was creating.
I have used and seen this function in the past.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
         Char.Humanoid.Died:Connect(function()
            --do code
         end)
    end)
end)

But I was wondering if there was possible a one-line function that I can call to see if there dead or not by returning a bool.

Example:

Player:IsDead() -- If dead true, else false.

I was thinking about
Humanoid:GetState() == Enum.HumanoidStateType.Dead
But I think exploiters can spoof this and easily make this statement useless.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
        not Char.Humanoid.Died:Connect(function()
            --do code
         end)
    end)
end)

You can just add a Not statement before the Died event.

1 Like

Im glade your good at building because it seems scripting is not a good look for you.
image
:clap:
Jokes aside, this would never work due to lua’s syntax and the way lua is structured also I made it clear im not looking to use Char.Humanoid.Died:Connect(function().

4 Likes

You could always check if the health equals to 0, every time it changes?

1 Like

But I was wondering if there was possible a one-line function that I can call to see if there dead or not by returning a bool.

I was looking for more of a one-lined function.
This is also very unpractical and could cause performance problems.

If i was to do it this way I would check if a descendant leaving the workspace is a character, if so there dead.

^^^ this is still unpractical.

if it’s on the server then I don’t believe exploiters can spoof HumanoidState though I may be wrong according to other people, also I don’t see what’s wrong with the current code you have

Hey, that isn’t very kind of you. I am still learning and you shouldn’t have judged me like that.
Please don’t make a joke out of my experience. It’s never funny.

Anyways, humanoid:GetState() Seems to be the most effective way of getting the state.

9 Likes

My bad, I think Humanoid:GetState() is exploitable tho.

if it is a localscript, yes, it it is exploitable on the client. Only serversided scripts are anti exploitable. You could get an anticheat to make it unexploitable.

Thank you for apologizing