Alright, I already know how to do it, but I have a weird issue when I rotate the brick to face the part in question. The video of the problem is here: https://youtu.be/dgF7W9D8kEY The problem is that the part I want to turn moves off the base of the turret which looks really bad. How could I fix it? The script is as follows:
function FindClosestPerson() for _,v in pairs(game.Players:GetChildren()) do if v.Character:FindFirstChild("Torso") ~= nil and v.Character:FindFirstChild("Humanoid") ~= nil and v.Character.Humanoid.Health > 0 then if (v.Character.Torso.Position - script.Parent.Union.Position).magnitude <= 20 then if v:GetRankInGroup(2874380) < 255 then return v.Character.Torso end else return nil end end end end function NoTarget() script.Parent:SetPrimaryPartCFrame(script.Parent.Part.CFrame * CFrame.fromEulerAnglesXYZ(0,0.01,0)) end function Aim(TargetTorso) script.Parent.Union.CFrame = CFrame.new(script.Parent.Union.CFrame.p,TargetTorso.CFrame.p) end while true do local TargetTorso = FindClosestPerson() wait() print(TargetTorso) if TargetTorso == nil then NoTarget() else Aim(TargetTorso) end end
Rather than rotating the union, weld it to a Cylinder part that has the radius of rotation you desire. Rotate said cylinder.
Make the thing you want to rotate a model, and place a invisible part at the bottom. The turret will rotate on the center of this part. Now go to the model's properties, and find PrimaryPart
. Set this to the invisible part on the bottom of your model. Now here's what I use to rotate models, it's not my scripting, forgive me if it's not efficient:
local model = workspace.model --The model of the turret model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(45), 0)) -- This rotates the model 45 degress
Accept if this helped