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

attempt to compare number < boolean?

Asked by 3 years ago

so i tried making a script that detects when the player's health decreases, but i kept getting "attempt to compare number < boolean". i'm pretty sure the boolean value is "newHealth", but how can that be a boolean value? here's the code (it's a local script, in StarterCharacterScripts)

local char = script.Parent
local hum = char:FindFirstChild("Humanoid")
local oldHealth = hum.Health

hum.HealthChanged:Connect(function(newHealth)

    if math.abs(oldHealth - newHealth) <= 10 > 1 then
        --code
    end
end)

thanks in advance

2 answers

Log in to vote
0
Answered by 3 years ago

Nevermind, I had to change the if statement to this

if math.abs(oldHealth - hum.Health) <= 10 and math.abs(oldHealth - hum.Health) > 1 then
    --code
end
0
The moment I realized I blooped up. MAD_DENISDAILY2 137 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

What XD_Destroyer1234 meant:


local char = script.Parent local hum = char:FindFirstChild("Humanoid") local oldHealth = hum.Health if math.abs(oldHealth - hum.Health) <= 10 and math.abs(oldHealth - hum.Health) > 1 then --code end

WARNING: DO ACCEPT THIS ANSWER

lol

0
it worked actually XD_Destroyer1234 4 — 3y
0
Wat? MAD_DENISDAILY2 137 — 3y
0
Hold up. I didn’t see that you made this question?!? Oops MAD_DENISDAILY2 137 — 3y
0
rip XD_Destroyer1234 4 — 3y
0
Wat if u accept ur own answer? MAD_DENISDAILY2 137 — 3y

Answer this question