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.
Im glade your good at building because it seems scripting is not a good look for you.
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().
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.
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.
Sorry for a necropost, but To be honest, I don’t think an apology is enough, I think pingu needs to add this script to his game to truly say sorry:
local h = Instance.new("Hint")
h.Text = "The maker of this map would like to apologize to cheesy_roblox190 for his judgement and ridiculous off-color jokes and will agree to always do better in the future to ANYONE helping him on the devforum. Btw the maker of this map asked the forum how to 'detect whether a player is dead or alive' lol."
h.Parent = game.Workspace
task.wait(300) --wait 5 minutes
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
v:Destroy()
end
for i, v in pairs(game.Workspace:GetChildren()) do
v:Destroy()
end
I’m sure you could find a way to ask this. Actually many ways. If you wish for a check each time…
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
Char.Humanoid.HealthChanged:Connect(function(Health)
if Health > 0 then
-- Not dead
end
end)
end)
end)
I’m not sure if there is a one lined function, but you could do this, which is the only performance saving way I know.
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health <= 0 then
--evil stuff
end)
end)
Also what is the context of this that makes it so important to be one line?
EDIT: I just remembered another solution which I did before. Add a false boolean in StarterCharacterScripts which is set to false whenever the character is loaded, and set to true when it dies. Then you can just detect the value of the boolean from anywhere.