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

Can't compare userdata to a number?

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:
local intValue = script.Parent.IntValue

local restValue = 0
local currentKey = 5
local table = workspace.Folder:GetChildren()

restValue = #table - currentKey

if restValue  > 5 and intValue < restValue then
	currentKey = currentKey+ intValue.Value
elseif restValue <= 5 and intValue >= restValue then
	currentKey= 1
end

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

Thank for you guys help!

1 answer

✓ Accepted answer

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.

local intValue = script.Parent.IntValue

local restValue = 0
local currentKey = 5
local table = workspace.Folder:GetChildren()

restValue = #table - currentKey

if restValue  > 5 and intValue < restValue then
    currentKey = currentKey+ intValue.Value
elseif restValue <= 5 and intValue.Value >= restValue then --here
    currentKey= 1
end

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