How could I check how many studs away a part is from another part. Such as, a part named Ice. And another named cream, if Ice got 10 studs away from cream, it would print "stop" Any ideas?
To find the distance between two points, you can use the following equation:
Distance = math.sqrt((PX1 - PX2)^2 + (PY1 - PY2)^2 + (PZ1 - PZ2)^2)
So, for your case, this might look like:
local Pos1 = Ice.Position local Pos2 = Cream.Position local Distance = math.sqrt((Pos1.X - Pos2.X)^2 + (Pos1.Y - Pos2.Y)^2 + (Pos1.Z - Pos2.Z)^2) if Distance < 10 then print("stop") end
This would need to be run on a loop or connected to an event, but it should give you an idea how to achieve this.
It won't let me post comments so I am just gonna post what my idea is,
You could make it so if it got (0, 5, 0) away from it than it will print stop,
That should be easy though, I am not fantastic but somewhere along lines like
if Ice.position = Vector3 (0, 5, 0) then print ("stop")
I expect to lose more points from this because it isn't a comment but this is all I can do for you, Sorry if it is wrong, I didn't make you a correct script I made you a code to represent my idea.