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

Can't compare userdata to a number?

Asked by 5 years ago

So im trying to make a test script to campare some value, but when i run it, it throw some error: attempt to compare userdata with number

  • Script:
01local intValue = script.Parent.IntValue
02 
03local restValue = 0
04local currentKey = 5
05local table = workspace.Folder:GetChildren()
06 
07restValue = #table - currentKey
08 
09if restValue  > 5 and intValue < restValue then
10    currentKey = currentKey+ intValue.Value
11elseif restValue <= 5 and intValue >= restValue then
12    currentKey= 1
13end

I don't really know the error mean and what Im doing wrong.

Thank for you guys help!

1 answer

Log in to vote
3
Answered by
Psudar 882 Moderation Voter
5 years ago
Edited 5 years ago

Oh, you messed up at line 10.

The UserData value is the intValue, but you forgot to do intValue.Value, so you're basically trying to compare the object itself, the userdata, with the restValue, a number.

01local intValue = script.Parent.IntValue
02 
03local restValue = 0
04local currentKey = 5
05local table = workspace.Folder:GetChildren()
06 
07restValue = #table - currentKey
08 
09if restValue  > 5 and intValue < restValue then
10    currentKey = currentKey+ intValue.Value
11elseif restValue <= 5 and intValue.Value >= restValue then --here
12    currentKey= 1
13end
Ad

Answer this question