Lock on tsb
Key Required

Lock on tsb

The Strongest BattlegroundsZrbihzrhsejseiheZrbihzrhsejseihe 29.8K views 15.8K executesUpdated Jan 16, 2025
5.0/ 5(1 votes)
10100% Positive
Lua Script•99 lines (4287 chars)
local Players = game:GetService("Players")
local camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

-- Create the GUI Button
local screenGui = Instance.new("ScreenGui", playerGui)
screenGui.Name = "LockOnGui"

local button = Instance.new("TextButton", screenGui)
button.Name = "LockOnButton"
button.Size = UDim2.new(0, 35, 0, 35) -- 35x35 pixels
button.Position = UDim2.new(0, 605, 0, -40) -- Adjusted to be 100 more pixels to the right
button.Text = "Lock On" -- Lock icon
button.TextScaled = true
button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
button.TextColor3 = Color3.fromRGB(255, 255, 255)
button.BackgroundTransparency = 0.4  -- Slight transparency to make the glow more visible

-- Glow Frame (for the glow effect)
local glowFrame = Instance.new("Frame", button)
glowFrame.Size = UDim2.new(1.2, 0, 1.2, 0)  -- Slightly bigger than the button for the glow effect
glowFrame.Position = UDim2.new(0, -5, 0, -5) -- Position the glow around the button
glowFrame.BackgroundTransparency = 1
glowFrame.BackgroundColor3 = Color3.fromRGB(0, 255, 0)  -- Glow color (green)

-- Add a UIGradient to simulate the glow
local glowGradient = Instance.new("UIGradient", glowFrame)
glowGradient.Color = ColorSequence.new(Color3.fromRGB(0, 255, 0), Color3.fromRGB(0, 255, 0))
glowGradient.Transparency = NumberSequence.new(0.5, 1)  -- Make the glow fade out
glowGradient.Rotation = 45  -- Slight rotation for the glow effect

-- Make the glow invisible initially
glowFrame.Visible = false

-- Variables
local isLockedOn = false
local target = nil

-- Function to find the nearest target (players and NPCs) within a 50-stud radius
local function getNearestTarget()
    local nearest = nil
    local shortestDistance = 50 -- Set maximum distance to 50 studs
    local playerPos = player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character.HumanoidRootPart.Position

    if not playerPos then return nil end

    -- Check all potential targets (Players and NPCs)
    for _, obj in ipairs(workspace:GetDescendants()) do
        if obj:IsA("Model") and obj ~= player.Character and obj:FindFirstChild("Humanoid") and obj:FindFirstChild("HumanoidRootPart") then
            local distance = (obj.HumanoidRootPart.Position - playerPos).Magnitude
            if distance < shortestDistance then
                shortestDistance = distance
                nearest = obj
            end
        end
    end

    return nearest
end

-- Toggle Lock-On State
button.MouseButton1Click:Connect(function()
    isLockedOn = not isLockedOn -- Toggle state
    if isLockedOn then
        button.BackgroundColor3 = Color3.fromRGB(102, 255, 102) -- Lighter green when enabled
        glowFrame.Visible = true  -- Show the glow effect
        -- Auto-lock on the nearest target if not already locked
        if not target then
            target = getNearestTarget()
        end
    else
        button.BackgroundColor3 = Color3.fromRGB(50, 50, 50) -- Gray when disabled
        glowFrame.Visible = false  -- Hide the glow effect
        camera.CameraSubject = player.Character:FindFirstChild("Humanoid")
        target = nil
    end
end)

-- Continuously Update Camera Lock
game:GetService("RunService").RenderStepped:Connect(function()
    if isLockedOn and target then
        local humanoidRootPart = target:FindFirstChild("HumanoidRootPart")
        if humanoidRootPart and target:FindFirstChild("Humanoid").Health > 0 then
            -- Rotate camera to face the target's HumanoidRootPart while maintaining player's POV
            local targetPosition = humanoidRootPart.Position
            local cameraPosition = camera.CFrame.Position
            local direction = (targetPosition - cameraPosition).unit -- Get direction vector
            camera.CFrame = CFrame.new(cameraPosition, cameraPosition + direction) -- Update camera orientation
        else
            -- Reset if the target is invalid or out of range
            button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            glowFrame.Visible = false  -- Hide the glow effect
            camera.CameraSubject = player.Character:FindFirstChild("Humanoid")
            isLockedOn = false
            target = nil
        end
    end
end)

Features & Information

Locks onto players/npcs
#Tsb#Tsbg#Sbg#Lock on#The Strongest battlegrounds

Community Comments (1)

picklemonsterpicklemonsterJan 16, 2025(edited)

Whats Ur user

More Scripts for The Strongest Battlegrounds