Universal Script 📌
48.3k Views
199 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

Updates

  1. Script edited: Create script

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
Script hub
3.0M
1.1M
Bumped 3 hours ago
Key System

Script hub

#6 today

CanHub V2 200 GAMES KEYLESS

Script hub
167
7
22 hours ago
Script hub
277.5k
165.4k
Bumped 4 hours ago
Key System
Universal Script 📌
6.7k
17.0k
Bumped 4 hours ago
Script hub
1.7M
431.9k
Bumped 5 hours ago
Key System

Script hub

#7 today

Verified script badgeAxonic Hub | 50+ Games Supported

Universal Script 📌
2.5k
7.1k
Bumped 10 hours ago
Script hub
5.9k
86.5k
Bumped 10 hours ago

Script hub

SAGAZx Hub

Script hub
77.7k
274.5k
Bumped 11 hours ago
Key System