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
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.