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

"attempt to compare string with number" Error?

Asked by 5 years ago

The error appears to be in line 10, any ideas?

local Player = script.Parent.Parent.Parent.Parent.Parent
local oops = script.Parent.Parent.Parent.Oops
local HBidder = workspace.HighestBidder.Value
local HBid = workspace.HighestBid.Value
print(Player)

script.Parent.FocusLost:Connect(function()
local Text = script.Parent.Text
if tonumber(Text) then
    if tonumber(Text) > HBid then
        HBid = Text
        HBidder = Player
end
end
end)

1 answer

Log in to vote
3
Answered by
nilVector 812 Moderation Voter
5 years ago

The error describes exactly what you're doing wrong.

tonumber(Text) will return a number representation of Text. HBid, I'm assuming, is a string. How can a number be greater than a string (without getting into certain technicalities)? It can't. A number is a number, and a string is a string. What I think you did was that you used a StringValue for HBid when you should've been using an IntValue.

Additionally, I've noticed another mistake. You do:

local HBidder = workspace.HighestBidder.Value
local HBid = workspace.HighestBid.Value

and then later on, you try changing their values by doing

HBid = Text
HBidder = Player

That will not change their values. Initially, HBidder and HBid are not a reference to HighestBidder.Value and HighestBid.Value but rather strings whose values are equal to their values. Whenever you want to change ValueBase objects, you must refer to their object first and then assign a change to their Value property, so it should be more like this:

local HBidder = workspace.HighestBidder
local HBid = workspace.HighestBid

-- later on in the script
HBid.Value = Text
HBidder.Value = Player

Same thing if you want to check the Value. You must check HBidder.Value rather than HBidder and HBid.Value rather than HBid.

0
Please accept my friend request. I love you, no homo. You know what you’re doing, most deprecated code using geeks never get the message I give them into their brains. (This guy didn’t use deprecated code but others). User#19524 175 — 5y
0
everything goes okay until i get error "attempt to compare userdata with number" in line 10 -_- SuperBeeperman 30 — 5y
0
Are you using 'HBid' or 'HBid.Value' to compare? nilVector 812 — 5y
0
compare? SuperBeeperman 30 — 5y
0
Like check its value in an if-statement. nilVector 812 — 5y
Ad

Answer this question