Attempt to compare instance with number

SO. For some weird reason this script wont work.
I have a bunch of scripts just like this that work perfectly but for some reason this one just wont friggen work
I get an error message stating that it attempted to compare an instance to a value which is not true.

local function attemptToBuy(player)
	local money = player.leaderstats.Tokens

	if money then
		if money.Value >= cost then
			money.Value = money.Value - cost

			itemClone.Parent = container
			button:Destroy()
			local show = game.Workspace.Tycoon.AutoDropper9.BuyButton
			show.Transparency = 0
			show.CanCollide = true
			show.CanTouch = true
			local show2 = show.Label.TextLabel
			show2.Visible = true
			local show = game.Workspace.Tycoon.Wall6.BuyButton
			show.Transparency = 0
			show.CanCollide = true
			show.CanTouch = true
			local show2 = show.Label.TextLabel
			show2.Visible = true
			
		end
	end
end

What the heck is wrong?

Btw roblox gotta upgrade their error messages, they are not very helpful when it comes to specifics.

It’s about as helpful as it gets, it describes exactly what datatypes are being compared and what errors.

Is cost an instance?

2 Likes

If you’re bad at scripting, then this is literally why you’re complaining, the error message isn’t hard.

This just means you’re trying to compare a number with something that isn’t a number, in this casebook it is an instance. Can you tell us which is the error line of the code?

2 Likes

tell us which line of code has the error cuz we don’t know if cost is a number or an instance

Here you’re comparing a number with an Instance, so check if “cost” is an instance and if it is you should replace it with a number, since you can’t compare two different types.

1 Like

It is probably a ValueBase like the money variable.

Replace the “cost” with “cost.Value” and see if it works

2 Likes