Cframe becoming absurdly large number

this only happens sometimes

i wan him to teleport near an enemy and punch them
xMove and zMove are random numbers between -7 and 7

guy.PrimaryPart.CFrame = CFrame.lookAt(Vector3.new(target.PrimaryPart.Position.X-xMove, target.PrimaryPart.Position.Y, target.PrimaryPart.Position.Z-zMove), target.PrimaryPart.Position)

image

I was able to replicate the issue you are having using similar code:

The issue occurs when the at position and the lookAt position are the same (so both the first vector3 and the second vector3 are identical). This results in several NAN values in the CFrame. When you then try to give an object that CFrame as its near CFrame, it moves it waaaaaaaaaaay down, as it doesn’t know how to handle it.

In your particular case, this occurs when both xMove and zMove are equal to 0. I would recommend replacing your current x, y generation code with something like the following, which ensures x and y can’t both be 0 at the same time:

local x, y
repeat
	x = math.random(-7, 7)
	y = math.random(-7, 7)
until x ~= 0 or y ~= 0

you are a genius young man thank you