Attempt to compare boolean <= number

  1. What do you want to achieve?
    How to fix the error of this script.
  2. What is the issue?
    attempt to compare boolean <= number even though its a number
  3. What solutions have you tried so far?
    doing an:
if type(value)=="number" then 

Here is the script:

local oldHealth = script.Parent.Humanoid.MaxHealth

local remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Glorified")

local boxNow

local player


game.Players.PlayerAdded:Connect(function(plr)
	player = plr
end)

script.Parent.Humanoid.HealthChanged:Connect(function(newHealth)
	if type(newHealth)=="number" and newHealth <= oldHealth/2 and player ~= nil and player:IsA("Player") and script.Parent~=nil and not newHealth <= 0 then
		remote:FireClient(player,workspace.Enemies.R6)
		script.Parent.Humanoid.WalkSpeed = 0
		script.Parent.Staggered.Value = true
		script.Parent.CanDamage.Value = false
		for i, v in pairs(script.Parent:GetChildren()) do
			if v:IsA("Part")and not v.Name == "Bruh" then
				local box = Instance.new("SelectionBox", v)
				box.Transparency = 0
				box.Adornee = v
				box.SurfaceTransparency = 1
				box.LineThickness = 0.001
				box.Color3 = Color3.new(1, 0.333333, 0)
				boxNow = box
			end
		end
		task.wait(5)
		if script.Parent~= nil and script.Parent:FindFirstChild("Staggered") then
			script.Parent.Staggered.Value = false
			script.Parent.Humanoid.WalkSpeed = 12
			script.Parent.CanDamage.Value = true
			for i, v in pairs(script.Parent:GetChildren()) do
				if v:IsA("Part") then
					local box = v:FindFirstChild("SelectionBox")
					if box then
						box:Destroy()
					end
				end
			end
		else
			warn("Staggered is nil!")
		end
	end
end)

script.Parent.Humanoid.Died:Connect(function()
	for i, v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Part") then
			if v:FindFirstChild("SelectionBox") then
				repeat v.SelectionBox:Destroy() until not v:FindFirstChild("SelectionBox")
				task.wait(.2)
				script.Parent:Destroy()
			end
		end
	end
end)

All help would be appreciated!

you can do

if (type(value)=="number") then

I tried that, it didn’t work. Btw, I need more characters.

The problem is at the end of your if statement where you put:

and not newHealth <= 0 then

The interpreter thinks you’re turning newHealth into a bool because the not keyword flips a bool from true to false and vice versa. You should just do this instead:

if newHealth <= oldHealth/2 and player ~= nil and script.Parent ~= nil and newHealth > 0 then
    -- code
end

Thanks! It works. But I need more characters.