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

"attempt to compare string with number" Error?

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

✓ Accepted answer

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.

5 comments

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).

0

everything goes okay until i get error "attempt to compare userdata with number" in line 10 -_-

0

Are you using 'HBid' or 'HBid.Value' to compare?

0

compare?

0

Like check its value in an if-statement.

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