Im trying to make it so when my weapons are equipped, and near an NPC, it will lock onto that NPC boxing league style, like the camera will still be able to see the player, but it will be aiming at the NPC. Heres the code I have right now.
wait(3)
eq = false
script.Parent.Equipped:Connect(function(equipped)
eq = true
end)
script.Parent.Unequipped:Connect(function(equipped)
eq = false
end)
local ztor = game.Players.LocalPlayer.Character.HumanoidRootPart
local function FindTar()
local agro = 25
local vector3 = Vector3.new(25,25,25)
local magnitude = vector3.Magnitude
local target
for i, v in pairs(workspace:GetChildren()) do
local hum = v:FindFirstChild("Humanoid")
local tor = v:FindFirstChild("HumanoidRootPart")
if hum and tor and v ~= script.Parent then
if v:FindFirstChild("HumanoidRootPart"):FindFirstChild("Bad") then
else
if (ztor.Position - tor.Position).Magnitude < agro then
agro = (ztor.Position - tor.Position).Magnitude
target = tor
end
end
end
end
return target
end
while eq do
wait(1)
local tor = FindTar()
if tor and eq == true then
workspace.CurrentCamera.CameraSubject = tor.Parent.Humanoid
else
workspace.CurrentCamera.CameraSubject = ztor.Parent.Humanoid
end
end