Universal Lock On
Key RequiredUniversal

Universal Lock On

Universal Scriptyomanisaacyomanisaac 51.4K views 2.4K executesUpdated Oct 22, 2024
3.8/ 5(4 votes)
3175% Positive
Lua Script•72 lines (2168 chars)
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
            targetLock = true
        end
    end
end


local function updateLock()
    if lockedPlayer and lockedPlayer.Character then
        local torso = lockedPlayer.Character:FindFirstChild("HumanoidRootPart")
        if torso then
            workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position, torso.Position)
        end
    end
end


UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.C then
        if not targetLock then
            lockOntoPlayer()
        else
            mouse.TargetFilter = nil
            lockedPlayer = nil
            targetLock = false
        end
    end
end)

RunService.RenderStepped:Connect(function()
    if targetLock then
        updateLock()
    end
end)

Features & Information

Made by Yomanisaac Press C to lock on to player

Community Comments (4)

traxtaytraxtayApr 17, 2025

i loved the old version with one target only please bring back the version with one target only i need it for forsaken

yomanisaacyomanisaacJun 29, 2025

there was no old version

slightyeffectiveslightyeffectiveMay 13, 2026

i made an account just to like this script, its amazing thank you.

AkytaAkytaMay 15, 2026

i have some questions about this script

More Scripts for Universal Scripts