Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to compare number < boolean?

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

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

1 comment

0

The moment I realized I blooped up.

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

5 comments

0

it worked actually

0

Wat?

0

Hold up. I didn’t see that you made this question?!? Oops

0

rip

0

Wat if u accept ur own answer?

This discussion is preserved as it was. New answers, comments, and votes are closed.