Attempt to compare number and boolean

I need another pair of eyes to take a look at this, mine must be failing me. Where am I comparing a number with a boolean? I marked the line below that is producing the error.

local icevalue = plr.Ice.Value
local pet = game.ReplicatedStorage.ShopItems.Pets:FindFirstChild(petName)
print(typeof(pet.Level.Value)) --Tested, prints 'number'
print(typeof(plr.Level.Value)) --Tested, prints 'number'
if not pet or 
	not plr:FindFirstChild("AvailablePets") or plr.AvailablePets:FindFirstChild(petName) or 
	not plr.Level.Value >= pet.Level.Value or -- Line that creates error
	not pet:FindFirstChild("Price") or icevalue < pet.Price.Value then
	return false
end

Try wrapping your boolean expressions with parentheses to make it easier to understand the logic and avoid potential confusion with operator precedence.

if (not pet)
	or (not plr:FindFirstChild("AvailablePets"))
	or (plr.AvailablePets:FindFirstChild(petName))
	or (not (plr.Level.Value >= pet.Level.Value))
	or (not pet:FindFirstChild("Price"))
	or (icevalue < pet.Price.Value) then
	return false
end
2 Likes

Oddly enough, that fixed the issue. Thank you. I’m still confused as to what went wrong with my original code.

This is what went wrong with your original code. Some of your operators had higher precedence and ran in an order you weren’t expecting. For example, the not operators in your conditions were only operating against the first operand, not the result of the comparison of all operands.

Relational operators: Programming in Lua : 3.2
Logical operators: Programming in Lua : 3.3
Precedence in Lua: Programming in Lua : 3.5

3 Likes