local isLockedOn = false
local localPlayer = [Link]
local currentTarget = nil
local function findValidTarget()
local camera = [Link]
local character = [Link]
if not character then return nil end
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return nil end
local closestPlayer = nil
local shortestAngle = [Link]
local fieldOfView = [Link](50)
local distanceRequirement = 1000
local redTeamExists = false
local blueTeamExists = false
for _, team in ipairs([Link]:GetTeams()) do
if [Link] == "Red Team" then
redTeamExists = true
elseif [Link] == "Blue Team" then
blueTeamExists = true
end
end
for _, player in ipairs([Link]:GetPlayers()) do
if player ~= localPlayer and [Link] then
local targetCharacter = [Link]
local targetHumanoidRootPart =
targetCharacter:FindFirstChild("HumanoidRootPart")
if targetHumanoidRootPart then
local teamName = [Link] and [Link]
if teamName and not (teamName == "Spectator" or teamName ==
"Spectators" or teamName == "AFK") then
if (redTeamExists or blueTeamExists) and teamName ~=
[Link] then
local distance = ([Link] -
[Link]).Magnitude
if distance <= distanceRequirement then
local targetDirection =
([Link] - [Link]).unit
local cameraDirection = [Link]
local angle =
[Link](cameraDirection:Dot(targetDirection))
if angle < fieldOfView and angle < shortestAngle then
closestPlayer = player
shortestAngle = angle
end
end
elseif not redTeamExists and not blueTeamExists then
local distance = ([Link] -
[Link]).Magnitude
if distance <= distanceRequirement then
local targetDirection =
([Link] - [Link]).unit
local cameraDirection = [Link]
local angle =
[Link](cameraDirection:Dot(targetDirection))
if angle < fieldOfView and angle < shortestAngle then
closestPlayer = player
shortestAngle = angle
end
end
end
end
end
end
end
return closestPlayer
end
local function updateLockOn()
local camera = [Link]
if isLockedOn and currentTarget then
local targetPosition = [Link]
local cameraPosition = [Link]
[Link] = [Link](cameraPosition, targetPosition)
end
end
local function onKeyPress(input)
if [Link] == [Link].Z then
if isLockedOn then
isLockedOn = false
currentTarget = nil
else
local targetPlayer = findValidTarget()
if targetPlayer then
isLockedOn = true
currentTarget = targetPlayer
local targetHumanoid =
[Link]:FindFirstChildOfClass("Humanoid")
if targetHumanoid then
[Link]:Connect(function()
isLockedOn = false
currentTarget = nil
end)
end
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(function()
if isLockedOn and currentTarget then
local targetPlayer = currentTarget
if targetPlayer then
local camera = [Link]
local targetPosition = [Link]
local cameraPosition = [Link]
[Link] = [Link](cameraPosition, targetPosition)
else
isLockedOn = false
end
end
end)
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)