So I'm trying to make a model appear when a zombie dies to delete it and have it explode the code I am using is this
health = script.Parent:findFirstChild("Humanoid") debounce = false local self = script.Parent:clone() while true do wait(0.1) if (health.Health == 0) then if (debounce == true) then return end debounce = true wait(1) t = game.Lighting.Part:Clone() t.Parent = game.Workspace wait(10) t:remove() local clone = self:clone() clone.Parent = game.Workspace clone:MakeJoints() script.Parent:remove() end end
and I've tried changing it to the negatives I've been getting but that hasn't worked so I want a way to avoid negative health
Use "math.clamp." Math.clamp will set the first argument to the third argument if it's greater than the third argument, and it will set the first argument to the second argument if it's below the second argument. Otherwise, it will return the first argument. This will also work with decimals.
Usage: math.clamp(valueToClamp, minValue, maxValue)
How to use:
print(math.clamp(5, 0, 36)) --returns 5 print(math.clamp(-5, 0, 36)) --returns 0 print(math.clamp(37, 0, 36)) --returns 36
In your case, you should set the maxValue to the zombie's max health.
local sign = math.sign(health.Health) if sign == -1 then health.Health = 0 elseif sign == 0 then -- code else --[[ This if the Humanoid Health has not died yet. --]] -- code end -- This will get your Health and return -1 if it exits natural order. -- ...and 0 for neutral, 1 for natural.