Head Aimlock Universal BEST IN FIRST PERSON
Key RequiredUniversal

Head Aimlock Universal BEST IN FIRST PERSON

Universal Scriptmaxmaster3602maxmaster3602 24.7K views 622 executesUpdated Jul 8, 2024
5.0/ 5(2 votes)
20100% Positive
Lua Script•83 lines (2698 chars)
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer

local cursorLocked = false
local connection

-- Create and set up the GUI
local gui = Instance.new("ScreenGui")
local textLabel = Instance.new("TextLabel")

gui.Name = "CursorLockGui"
gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

textLabel.Name = "LockStatusLabel"
textLabel.Parent = gui
textLabel.Text = "Cursor Unlocked"
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.Position = UDim2.new(0.5, -100, 0, 0)
textLabel.TextScaled = true
textLabel.BackgroundTransparency = 0.5
textLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
textLabel.Visible = true

-- Function to find the closest player's head
local function findClosestPlayerHead()
    local closestPlayer = nil
    local closestDistance = math.huge

    for _, player in pairs(Players:GetPlayers()) do
        if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Head") then
            local head = player.Character.Head
            local distance = (LocalPlayer.Character.Head.Position - head.Position).Magnitude
            if distance < closestDistance then
                closestDistance = distance
                closestPlayer = head
            end
        end
    end

    return closestPlayer
end

-- Function to lock the cursor to the closest player's head
local function lockCursorToClosestHead()
    local closestHead = findClosestPlayerHead()
    if closestHead then
        UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
        connection = RunService.RenderStepped:Connect(function()
            local camera = workspace.CurrentCamera
            camera.CFrame = CFrame.new(camera.CFrame.Position, closestHead.Position)
        end)
        textLabel.Text = "Cursor Locked"
    end
end

-- Function to unlock the cursor
local function unlockCursor()
    UserInputService.MouseBehavior = Enum.MouseBehavior.Default
    if connection then
        connection:Disconnect()
        connection = nil
    end
    textLabel.Text = "Cursor Unlocked"
end

-- Function to handle mouse button press
local function onMousePress(input, gameProcessedEvent)
    if not gameProcessedEvent then
        if input.UserInputType == Enum.UserInputType.MouseButton2 then
            if cursorLocked then
                unlockCursor()
            else
                lockCursorToClosestHead()
            end
            cursorLocked = not cursorLocked
        end
    end
end

UserInputService.InputBegan:Connect(onMousePress)

Features & Information

Locks Players Curser to nearest players head

Community Comments (6)

PorshePorsheJul 8, 2024(edited)

How do I activate it

maxmaster3602maxmaster3602Jul 8, 2024(edited)

Right CLick

marvmarvJul 8, 2024(edited)

yo this one works you right click on mouse to lock on to player and shoot i tested it in a first person shooter

maxmaster3602maxmaster3602Jul 9, 2024(edited)

Thanks for your great feedback marv shout i carry this script on maybe a GUI?

marvmarvJul 9, 2024(edited)

@maxmaster3602 yeah you could put it on a gui

silly_silly_Jul 11, 2024(edited)

works (Supports) solara :D

More Scripts for Universal Scripts