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

Can someone help with this error in comparing two sizes/vector stufff?

it says attempt to compare two userdata values

** if game.Workspace.Baseplate.Size >= Vector3.new(251,20,251) then** x = math.random(-255, 255) y = math.random(6, 30) z = math.random (-255, 255) end

The if - then is where the error occurs

2 comments

0

please use code blox

0

Can't compare them straight up like that. Try getting the scalar values (e.g. Baseplate.Size.x > 251)

1 answer

✓ Accepted answer

You can't compare Vector3's to see if they're less than or more than. Instead, compare their components.

function compare(x, y)
       if x.X >= y.X and x.Y >= y.Y and x.Z >= y.Z then
              return true
       end
       return false
end

if compare(workspace.Basplate.Size, Vector3.new(251, 20, 251)) then
       x, y, z = math.random(-255, 255), math.random(6, 30), math.random(-255, 255)
end

2 comments

0

It works but could you explain it a lil cuz im new to this stuff

0

The function 'compare' has two parameters: 'x' and 'y', which we will use to compare Vector3's when we pass them as arguments in the if statement. The function will check if all values of 'x' are more than the values of 'y'. If they are, then we will return true, else it will return false. In the if statement, we're going to pass two arguments which are Vector3's. If it's true, then we will procee

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