Y axis Aimbot Script not Working

I want to achieve in making an only Y Axis aimbot script. Pretty much aimbot but only for the up and down axis. The issue is that I can’t get it to do the right thing. I got help from discord and I fiddled with it using negative CFrames. Here is as close as I have to an aimbot Y axis on enemy:

-- Face Enemy with Camera on Y-Axis.
local function FaceTarget()
	local Enemy = FindTarget()
	if Enemy then

		-- Auto adjust Enemies Y axis

		print(Enemy.Parent)

		local direction = -(Enemy.Position - Camera.CFrame.Position)
		local XZ = Vector3.new(1,0,1)

		local directionToLookAt = Camera.CFrame.Position + Camera.CFrame.LookVector * (direction * XZ).Magnitude + Vector3.new(0,direction.y,0)

		print(directionToLookAt)
		Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, directionToLookAt)




	else -- No Enemy

		-- Return Camera back to normal original spot

		-- Camera.CFrame = CFrame.new(0,0,0)
	end
end
RunService.RenderStepped:Connect(FaceTarget)

Enemy is the enemies’ HumanoidRootPart

I think you can give this a try!
Hope I understood what you are looking for. I might have some typos, so let me know if the code runs.

-- Face Enemy with Camera on Y-Axis.
local function FaceTarget()
	local Enemy = FindTarget()
	if Enemy then

		-- Auto adjust Enemies Y axis
        
        --- [[Changed code from here]]
        local yDiff = (Enemy.Position.Y - Camera.CFrame.Position.Y)
        local xzDiff = (Vector2.new(Enemy.Position.X, Enemy.Position.Z) - Vector2.new(Camera.CFrame.Position.X, Camera.CFrame.Position.Z)).Magnitude

		Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, Camera.CFrame.Position + Camera.CFrame.LookVector*xzDiff + Camera.CFrame.UpVector*yDiff)
        --- [[to here]]

	else -- No Enemy

		-- Return Camera back to normal original spot

		-- Camera.CFrame = CFrame.new(0,0,0)
	end
end
RunService.RenderStepped:Connect(FaceTarget)

I got some help on Fiverr. I forgot about this thread! Thank you very much for your reply!

1 Like