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

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

Asked by 5 years ago

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

0
please use code blox Carforlife1 59 — 5y
0
Can't compare them straight up like that. Try getting the scalar values (e.g. Baseplate.Size.x > 251) ScrewDeath 153 — 5y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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
0
It works but could you explain it a lil cuz im new to this stuff Tacodragon777 -1 — 5y
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 Rare_tendo 3000 — 5y
Ad

Answer this question