How do I fix this?

Hello, I’m having an issue where whenever I use sphere.CFrame = CFrame.lookAt(sphere.Position, waypoint.Position), the sphere just goes to the black zone in Roblox…

No Errors.

			sphere.CFrame = CFrame.lookAt(sphere.Position, waypoint.Position)
			local dPositionX = designatedPosition.X  -- designated
			local dPositionY = designatedPosition.Y
			local dPositionZ = designatedPosition.Z

			if cPositionX < dPositionX then
				sphere.Position +=, 0, 0)
			elseif cPositionX > dPositionX then
				sphere.Position -=, 0, 0)

			if cPositionY < dPositionY then
				sphere.Position +=, .5, 0)
			elseif cPositionY > dPositionY then
				sphere.Position -=, .5, 0)

			if cPositionZ < dPositionZ then
				sphere.Position +=, 0, .5)
			elseif cPositionZ > dPositionZ then
				sphere.Position -=, 0, .5)

			currentPosition = sphere.Position
			designatedPosition = waypoint.Position

			cPositionX = currentPosition.X
			cPositionY = currentPosition.Y
			cPositionZ = currentPosition.Z

			dPositionX = designatedPosition.X
			dPositionY = designatedPosition.Y
			dPositionZ = designatedPosition.Z
		until currentPosition == designatedPosition
1 Like


sphere.CFrame =, waypoint.Position)

instead of using CFrame.lookAt. I don’t know what you’re trying to do though.

1 Like

I’m trying to make a part look at another part.

while task.wait() do
	workspace.a.CFrame =
		workspace.a.Position, -- a is the part that is looking
		workspace.o.Position -- o is the part the i move around

This code worked for me.

Can you explain the difference from my script though?

Didn’t fix it

You were using CFrame.lookAt() in your script, whereas in mine I am using
I am using with two arguments: a Vector3 Position, and a Vector3 LookAt.

Can you send a place file so I can see?

(14) test - Roblox

Place file. So I can see the all of the code, as I assume the original post is not all of it. Also,

It is important to note here that using the constructor version of instead of CFrame.lookAt is deprecated. Note that CFrame.lookAt without a third argument behaves identically to, so thats not the issue.

For more information on why you should use CFrame.lookAt (other than it being more readable), see the article here:

1 Like

Sorry, used to using

So do you think that the issue relates to me not setting a third argument?

I think your main issue here is trying to perfectly reach the waypoint by units of .5, which may end up never matching up due to floating point issues (.499999 does not equal .5). Try checking the distance between the two like this:

local distance = (designatedPosition - currentPosition).magnitude

if distance < 5 then
    -- Within 5 studs, either set directly or stop here

No, the third argument in CFrame.lookAt determines which direction is up, which has a default of,1,0). Unless it’s upside down, you don’t need to worry about it. Look at the docs for more info., b) == CFrame.lookAt(a, b)

Bit confusing, because .5 + .5 = 1, so how did it happen?

Floating point errors.

Floating point error in Python - GeeksforGeeks.

1 Like