Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't compare number to userdata? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

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

0
What is bicyclePrice1T ? User#5423 17 — 6y
0
Sorry, forgot about it, now it's in the script Tymberlejk 143 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

Ad

Answer this question