Why Cant I compare Vector3s when detecting change in position?

I’m writing a Script thats suppose to Detect the player’s Depth and hight, but I’m getting an Error:
“attempt to compare Vector3”

Is there a way to detect change in a Part’s position?

local player = game.Players.LocalPlayer
wait(.5)
local Character = player.Character


while wait() do
	if Character.HumanoidRootPart.Position <= Vector3.new(0,0,0) then
		print("Less Than")
		print(Character.HumanoidRootPart.Position)
	end
	
	if Character.HumanoidRootPart.Position >= Vector3.new(0,0,0) then
		print("Grater Than")
		print(Character.HumanoidRootPart.Position)
	end
end
1 Like

You can’t compare Vector3’s using <=, <, >, or >= because Roblox doesn’t implement __lt nor __le metamethods.

But a vector of 0, 0, 0 always has a magnitude of 0, so you can detect if the magnitude is >= 0?

1 Like

Thanks this is probably the solution, but is there a way to just use the Y axis for magnitude?

1 Like

I figured It out, I used a script @sjr04 made in another Post and just reworked it a bit.

1 Like

Could you link the post so future readers with the same problem can solve it?

1 Like

Don’t know if this post is still relevant but you could do every axis individually because it’s not technically comparing Vector3’s.

if Character.HumanoidRootPart.Position.X <= 0 and Character.HumanoidRootPart.Position.Y <= 0 and Character.HumanoidRootPart.Position.Z <= 0 then
print("Less Than")
	print(Character.HumanoidRootPart.Position)
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.