How to fix "attempt to compare boolean and number"?

  1. I want to create a shop script that takes away the price I put on the weapon.

  2. What is the issue? When I try make it check if the players Bucks are high enough to buy it, it gives the error. (“attempt to compare boolean and number”)

  3. What solutions have you tried so far? I tried googling it but I don’t see anything similar to it.

The code:

local ImageButton = script.Parent.ImageButton
local Bucks = game.Players.LocalPlayer:WaitForChild("leaderstats").Bucks
ImageButton.MouseButton1Click:Connect(function()
	local price = ImageButton:GetAttribute("Price")
	if not Bucks.Value < price then --The error is here
		Bucks.Value = Bucks.Value -price
	else
		print("Not enough bucks.")
	end
end)
1 Like

Try to put it inside tonumber().

And also if you want to perform this change for everyone you need to use RemoteFunction/RemoteEvent to communicate with server because this will change the value only on the client side and not for server.

Where do I put it though? When I put it on the fifth line next to “price” it errors and says “attempt to call a number value”

The not operator turns Bucks.Value into false and then false is compared to price. One way to fix this is using parenthesis:

if not (Bucks.Value < price) then

Here’s another option:

if Bucks.Value >= price then
1 Like

Thanks! The second option works for me :slight_smile:!