Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

what can i use for when a humanoids health changes?

Asked by
Jumbuu 110
7 years ago

i feel using if statements is a bad idea and will cause alot of bugs so what can i use instead that would be easier and less buggy

1
It sounds like you need the humanoid.changed event, but you need to be more specific if you want anything else. Also, read the guide for asking question. Give us a bit of code that you tried. GoldenPhysics 474 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

ROBLOX has a specific event for this called HealthChanged. It does exactly what it suggests: fires when the player's health changes. It's really easy to use;

local player=game.Players.LocalPlayer
local humanoid=player.Character.Humanoid
local currentHealth=humanoid.Health --getting the current health

humanoid.HealthChanged:connect(function(health) --Passes the parameter "health". It's just what it changed to
    local change=math.abs(currentHealth-health) --Getting the absolute value (Humanoid health is usually a decimal)
    print(player.Name.."'s health "..(currentHealth>health and "decreased by " or "increased by ")..change.."!") --This  will tell you whether the health increased or decreased
end)
Ad

Answer this question