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.
There is a way of doing this with :SetPrimaryPartCFrame()! In the second parameter of CFrame.new(), you are able to set where the part will face. Since your model has a primary part, this will make all the parts in the model face the same direction.
local part = Instance.new("Part", workspace) -- Create a part part.CFrame = CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0)) -- Move part 50 studs up from the origin and make it face towards the origin.
You can achieve the same thing in a model with a primary part by doing:
model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0))