Making turret look at mouse but not up/down

How could i make it so that this turret look at your mouse but not up or down, only turning around?

Code (local):

local run = game:GetService("RunService")
local mouse = game.Players.LocalPlayer:GetMouse()

run.Heartbeat:Connect(function()
	script.Floor.Value.CFrame = CFrame.lookAt(script.Floor.Value.Position,Vector3.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,mouse.Hit.Position.Z))
end)

This post should help for the method, however since it’s not working with C0 you can avoid the relativeToWorld CFrame which is the Part0 CFrame inversed.

local origin = Vector3.new(0,5,0)
local lookat = Vector3.new(0,0,5)

part.CFrame = CFrame.lookAt(origin,Vector3.new(lookat.X,origin.Y,lookat.Z))

Edit : Im pretty sure .RenderStepped is faster than .Heartbeat, as .RenderStepped is basically every frame.

Edit 2 : Actually, I just realized theres a better way. I believe this should work.

local origin = turret
local lookat = mouse.Hit -- .Hit is a CFrame

Part.CFrame = CFrame.lookAt(origin.Position,lookat.Position,lookat.UpVector)
3 Likes

‌‌‌‌‌‌i‌‌‌ ‌‌‌l‌‌‌o‌‌‌‌v‌‌‌e‌‌ y‌‌‌‌‌‌o‌‌‌‌u‌‌‌