
48.2k Views
169 Executions
Does it work?
No reports yetNo reports yet. Tried it? Be the first to say.
Also noticed:
Description
AAAAAAAAAH hold right mouse to lock on
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera
local LocalPlayer = Players.LocalPlayer
local lockOn = false
local targetPlayer = nil
-- get closest player
local function getClosestPlayer()
local closestPlayer = nil
local shortestDistance = math.huge
for _, player in pairs(Players:GetPlayers()) do
if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Head") then
local direction = (player.Character.Head.Position - LocalPlayer.Character.HumanoidRootPart.Position).unit
local forward = LocalPlayer.Character.HumanoidRootPart.CFrame.lookVector
local dotProduct = forward:Dot(direction)
local distance = (player.Character.Head.Position - LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if dotProduct > 0.9 and distance < shortestDistance then
closestPlayer = player
shortestDistance = distance
end
end
end
return closestPlayer
end
-- update thing so it doesnt freeze
local function updateLockOn()
if lockOn then
targetPlayer = getClosestPlayer()
if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then
local targetPosition = targetPlayer.Character.Head.Position
Camera.CFrame = CFrame.new(Camera.CFrame.Position, targetPosition)
end
end
Comments
0Log in to join the conversation. Login
No comments yet. Be the first!








