Universal Script 📌
1.2k Views
485 Executions

Open Source Lock On

Universal Script 📌
TruthfulJubi
TruthfulJubiFirst script
7 months 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

lock on, that's it really.

View Raw
--improved lock on
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()

local targetLock = false
local lockedPlayer = nil

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("HumanoidRootPart") then
            local character = player.Character
            local torso = character:FindFirstChild("HumanoidRootPart")
            local screenPos = workspace.CurrentCamera:WorldToScreenPoint(torso.Position)
            local mousePos = Vector2.new(mouse.X, mouse.Y)
            local distance = (mousePos - Vector2.new(screenPos.X, screenPos.Y)).Magnitude

            if distance < shortestDistance then
                shortestDistance = distance
                closestPlayer = player
            end
        end
    end

    return closestPlayer
end

local function lockOntoPlayer()
    local closestPlayer = getClosestPlayer()

    if closestPlayer and closestPlayer.Character then
        local torso = closestPlayer.Character:FindFirstChild("HumanoidRootPart")
        if torso then
            mouse.TargetFilter = torso
            lockedPlayer = closestPlayer


Comments

1
Log in to join the conversation. Login
jack_kennedy's profile picture
jack_kennedy5 months ago

tuffy

1

Tags

More universal scripts

See all
Script hub
7.5k
23.3k
Bumped 10 hours ago
Script hub
38.3k
166.3k
Bumped 10 hours ago

Script hub

Sp3arParvus

Script hub
148
8
Bumped 11 hours ago
Key System

Script hub

Zhonya Hub

Script hub
31.8k
7.6k
Bumped 13 hours ago
Key System
Paid
Universal Script 📌
257
17
Approved 14 hours ago