Universal Script 📌
48.2k Views
169 Executions

lock on

Universal Script 📌
Vortex
VortexPublished 5
2 years ago
Get an executor
Please login to perform these actions:

Does it work?

No reports yet

No reports yet. Tried it? Be the first to say.

Also noticed:

Description

AAAAAAAAAH hold right mouse to lock on

View Raw
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

0
Log in to join the conversation. Login
No comments yet. Be the first!

More universal scripts

See all
Universal Script 📌
3.8k
184.5k
Bumped 4 hours ago
Script hub
412
41
5 hours ago
Universal Script 📌
28.6k
663.4k
Bumped 7 hours ago
Script hub
13.8k
2.7k
Bumped 9 hours ago
Key System
Paid
Script hub
263.7k
88.1k
Bumped 10 hours ago
Key System
Universal Script 📌
2.9k
9.5k
Bumped 10 hours ago
Universal Script 📌
668
38
Approved 10 hours ago
Universal Script 📌
710
43
Approved 10 hours ago