How to compare coordinates?

Hi, I’m currently trying to create a script to compare coordinates.
My goal is this: if the coordinates of one part are too close to another, it is deleted.

My current script (dont work):

wait(2)
for i, v in pairs(script.Parent.Parent:GetChildren()) do
	print(v)
	if v.Position - script.Parent.Position <= Vector3.new(40, v.Position.Y, v.Position.Z) then
		print("del")
		script.Parent:Destroy()
		
	end
end

Thanks to anyone gives help!

I would do something like this:


for i, v in pairs(script.Parent.Parent:GetChildren()) do
	print(v)
	if (v.Position - script.Parent.Position).Magnitude <= 40 then
		print("del")
		script.Parent:Destroy()		
	end
end

This essentially does the same thing as you did, except it uses magnitude, which is the size of the difference between the two positions.

1 Like

Thanks! I didn’t know about the “Magnitude” feature!

1 Like

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