Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can't compare number to userdata? [SOLVED]

So I was trying to make a button green if the player has enough money and gray, if the player doesn't have enough money. The problem is, I can't compare his money value and the price of the item. The code looks like this:

-- Script
game.Players.PlayerAdded:connect(function(plr)
	local money = plr:WaitForChild("leaderstats").Money.Value
	local bicyclePrice1T = math.random(2, 20) * 5
	bicyclesImage.MouseButton1Down:connect(function()
		if money >= bicyclePrice1T then
			bBuyButton1A.BackgroundColor3 = BrickColor.Green().Color
		else
			bBuyButton1A.BackgroundColor3 = BrickColor.Gray().Color
		end
	end)
end)

And it shows me this error:

10:33:09.862 - ServerScriptService.InternetScript:491: attempt to compare number with userdata

Thanks for reading

2 comments

0

What is bicyclePrice1T ?

0

Sorry, forgot about it, now it's in the script

1 answer

I fixed the problem:

-- Script
game.Players.PlayerAdded:connect(function(plr)
	local money = plr:WaitForChild("leaderstats").Money
	local bicyclePrice1T = math.random(2, 20) * 5
	bicyclesImage.MouseButton1Down:connect(function()
		if money.Value >= bicyclePrice1T then
			bBuyButton1A.BackgroundColor3 = BrickColor.Green().Color
		else
			bBuyButton1A.BackgroundColor3 = BrickColor.Gray().Color
		end
	end)
end)

Scratch that, I actually needed to define the money and access its value while comparing it to bicyclePrice1T. Problem solved and now it works just fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.