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

1 comment
Thanks!