I am trying to make a turret that has a model as its parent rotate towards the direction of the nearest player within 50 studs. Currently I am using a cylinder as the range since my scripting isn't advanced. Here is my current script:
tuching = false
script.Parent.Touched:connect(function(part)
if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
print('touched')
tuching = true
wait()
script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.base.CFrame.p, Vector3.new(0,0,part.CFrame.Z)))
end
end)
script.Parent.TouchEnded:connect(function(part)
if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
print('no more tuch')
tuching = false
end
end)
I am looking for a proper :SetPrimaryPartCFrame() method of facing towards a part with it looking up and down a.k.a without the Y axis.

3 comments
Sorry if I didn't completely answer your question, but with what I have said I think you will be able to figure out the rest ;)
Thank you but I am trying to make it ignore the Y value to prevent it from going up and down and only look from left to right
No problem, if this is what you were looking for, please accept/upvote my answer :)