What's new
Heapleak - Scripthub

Get the most out of HeapLeak by creating a free account! Once signed in, you’ll gain full access to restricted content, be able to share your own scripts, and participate in our member-only discussions.

MistahMorningStar lock on script comm'd by him let me post.

Version / Update: v1.0.0
Download / Script Link
-- LocalScript in StarterPlayerScripts

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local lockedTarget = nil
local lockOnKey = Enum.KeyCode.Z
local maxLockDistance = 100

local enemyFolder = workspace:WaitForChild("Live")

-- =====================
-- GUI SETUP
-- =====================
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "LockOnGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = player.PlayerGui

local frame = Instance.new("Frame")
frame.Size = UDim2.new(0, 180, 0, 50)
frame.Position = UDim2.new(0.5, -90, 0.08, 0)
frame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
frame.BackgroundTransparency = 0.3
frame.BorderSizePixel = 0
frame.Parent = screenGui

local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 10)
corner.Parent = frame

local statusLabel = Instance.new("TextLabel")
statusLabel.Size = UDim2.new(1, 0, 0.5, 0)
statusLabel.Position = UDim2.new(0, 0, 0, 0)
statusLabel.BackgroundTransparency = 1
statusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
statusLabel.Text = "🔴 LOCK-ON: OFF"
statusLabel.TextScaled = true
statusLabel.Font = Enum.Font.GothamBold
statusLabel.Parent = frame

local targetLabel = Instance.new("TextLabel")
targetLabel.Size = UDim2.new(1, 0, 0.5, 0)
targetLabel.Position = UDim2.new(0, 0, 0.5, 0)
targetLabel.BackgroundTransparency = 1
targetLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
targetLabel.Text = ""
targetLabel.TextScaled = true
targetLabel.Font = Enum.Font.Gotham
targetLabel.Parent = frame

local function setGuiLocked(target)
if target then
statusLabel.Text = "🟢 LOCK-ON: ON"
statusLabel.TextColor3 = Color3.fromRGB(80, 255, 80)
targetLabel.Text = "Target: " .. target.Name
else
statusLabel.Text = "🔴 LOCK-ON: OFF"
statusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
targetLabel.Text = ""
end
end

-- =====================
-- LOCK-ON LOGIC
-- =====================
local function getClosestEnemy()
local character = player.Character
if not character then return nil end
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return nil end

local closest = nil
local closestDist = maxLockDistance

for _, enemy in ipairs(enemyFolder:GetChildren()) do
-- Skip the local player's own character
if enemy == character then continue end

-- Skip teammates
local enemyPlayer = Players:GetPlayerFromCharacter(enemy)
if enemyPlayer and enemyPlayer.Team == player.Team then continue end

local enemyHRP = enemy:FindFirstChild("HumanoidRootPart")
local humanoid = enemy:FindFirstChild("Humanoid")

if enemyHRP and humanoid and humanoid.Health > 0 then
local dist = (hrp.Position - enemyHRP.Position).Magnitude
if dist < closestDist then
closestDist = dist
closest = enemy
end
end
end

return closest
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == lockOnKey then
if lockedTarget then
lockedTarget = nil
setGuiLocked(nil)
else
lockedTarget = getClosestEnemy()
setGuiLocked(lockedTarget)
end
end
end)

RunService.RenderStepped:Connect(function()
if not lockedTarget then return end

local character = player.Character
if not character then return end
local hrp = character:FindFirstChild("HumanoidRootPart")
local enemyHRP = lockedTarget:FindFirstChild("HumanoidRootPart")
local humanoid = lockedTarget:FindFirstChild("Humanoid")

if not enemyHRP or not humanoid or humanoid.Health <= 0 then
lockedTarget = nil
setGuiLocked(nil)
return
end

local dist = (hrp.Position - enemyHRP.Position).Magnitude
if dist > maxLockDistance then
lockedTarget = nil
setGuiLocked(nil)
return
end

local targetPos = enemyHRP.Position + Vector3.new(0, 1.5, 0)
local camPos = camera.CFrame.Position
camera.CFrame = CFrame.new(camPos, targetPos)
end)
[ View More ]
44242d95-0402-4080-8258-f1f3dd01e897.webp


Press Z to lock on, made by cladue.ai what a awesome AI!!!!!!
 
Back
Top