Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Fully copyright, dont reupload.
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- local player = Players.LocalPlayer
- local mouse = player:GetMouse()
- local lockedPlayer = nil
- local isLocked = false
- local lockDistance = 120 -- Distance threshold to lock onto a player
- local camera = workspace.CurrentCamera
- -- Function to create the GUI
- local function createGui()
- -- Check if GUI already exists
- if player.PlayerGui:FindFirstChild("LockOnStatusGui") then
- return player.PlayerGui.LockOnStatusGui, player.PlayerGui.LockOnStatusGui.StatusFrame.StatusText
- end
- -- Enhanced GUI Setup
- local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
- ScreenGui.Name = "LockOnStatusGui"
- local StatusFrame = Instance.new("Frame", ScreenGui)
- StatusFrame.Name = "StatusFrame"
- StatusFrame.AnchorPoint = Vector2.new(0.5, 0.5)
- StatusFrame.Position = UDim2.new(0.5, 0, 0.1, 0) -- Positioned at the top
- StatusFrame.Size = UDim2.new(0, 400, 0, 70)
- StatusFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
- StatusFrame.BackgroundTransparency = 0.2
- StatusFrame.BorderSizePixel = 0
- StatusFrame.Visible = true
- -- Add UI Corner for rounded corners
- local UICorner = Instance.new("UICorner", StatusFrame)
- UICorner.CornerRadius = UDim.new(0, 15)
- -- Add a UI Gradient for a more epic look
- local UIGradient = Instance.new("UIGradient", StatusFrame)
- UIGradient.Color = ColorSequence.new{
- ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
- ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 0, 255))
- }
- UIGradient.Rotation = 45 -- Set rotation for a diagonal gradient effect
- -- Add a shadow effect for depth
- local Shadow = Instance.new("Frame", StatusFrame)
- Shadow.Size = UDim2.new(1, 10, 1, 10)
- Shadow.Position = UDim2.new(0, -5, 0, -5)
- Shadow.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- Shadow.BackgroundTransparency = 0.7
- Shadow.ZIndex = -1
- local ShadowCorner = Instance.new("UICorner", Shadow)
- ShadowCorner.CornerRadius = UDim.new(0, 15)
- -- Status text setup
- local StatusText = Instance.new("TextLabel", StatusFrame)
- StatusText.Name = "StatusText"
- StatusText.Size = UDim2.new(1, 0, 1, 0)
- StatusText.Font = Enum.Font.GothamBlack
- StatusText.TextSize = 30
- StatusText.TextColor3 = Color3.fromRGB(255, 255, 255)
- StatusText.BackgroundTransparency = 1
- StatusText.Text = "Finding player..."
- -- Add a text stroke for a glowing effect
- StatusText.TextStrokeTransparency = 0.2
- StatusText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
- -- Add mobile "Locking/Unlocking" button with epic design
- local LockButton = Instance.new("TextButton", ScreenGui)
- LockButton.Name = "LockButton"
- LockButton.Size = UDim2.new(0, 200, 0, 50)
- LockButton.Position = UDim2.new(0.5, 0, 0.9, -4) -- Positioned at the bottom-center
- LockButton.AnchorPoint = Vector2.new(0.5, 0.5)
- LockButton.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
- LockButton.Text = "Locking/Unlocking"
- LockButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- LockButton.TextScaled = true
- LockButton.Font = Enum.Font.GothamBold -- Match the font with StatusText
- -- Add UI corner for button
- local ButtonUICorner = Instance.new("UICorner", LockButton)
- ButtonUICorner.CornerRadius = UDim.new(0, 15)
- -- Add UI Gradient for button look
- local ButtonGradient = Instance.new("UIGradient", LockButton)
- ButtonGradient.Color = ColorSequence.new{
- ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)), -- Match colors with StatusText
- ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 0, 255))
- }
- ButtonGradient.Rotation = 90
- -- Add text stroke to button
- LockButton.TextStrokeTransparency = 0.2
- LockButton.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
- -- Function to animate button when clicked
- local function animateButton()
- -- Scale up the button
- local scaleUp = TweenService:Create(
- LockButton,
- TweenInfo.new(0.1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out),
- {Size = UDim2.new(0, 220, 0, 60)}
- )
- -- Scale down the button back to its original size
- local scaleDown = TweenService:Create(
- LockButton,
- TweenInfo.new(0.1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out),
- {Size = UDim2.new(0, 200, 0, 50)}
- )
- -- Play the animations in sequence
- scaleUp:Play()
- scaleUp.Completed:Wait() -- Wait for scaleUp to finish before scaling down
- scaleDown:Play()
- end
- -- Function to handle button click
- LockButton.MouseButton1Click:Connect(function()
- animateButton() -- Play the animation when the button is clicked
- toggleLock() -- Toggle the lock/unlock functionality
- end)
- return ScreenGui, StatusText
- end
- -- Create the GUI initially
- local gui, StatusText = createGui()
- -- Function to smoothly move the camera towards the target
- local function smoothCameraLock(targetPosition)
- local tween = TweenService:Create(
- camera,
- TweenInfo.new(0.01, Enum.EasingStyle.Linear),
- {CFrame = CFrame.new(camera.CFrame.Position, targetPosition)}
- )
- tween:Play()
- end
- -- Function to lock the mouse to a player's body (HumanoidRootPart)
- local function lockMouseToPlayer(targetPlayer)
- lockedPlayer = targetPlayer
- isLocked = true
- mouse.Icon = "rbxassetid://20329976" -- Optional: Change the mouse icon to indicate lock-on
- -- Update the status text
- StatusText.Text = "Locking onto " .. targetPlayer.Name
- -- Pulse animation for epic effect when locking onto a player
- TweenService:Create(gui.StatusFrame, TweenInfo.new(0.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {
- Size = UDim2.new(0, 420, 0, 90)
- }):Play()
- wait(0.3)
- TweenService:Create(gui.StatusFrame, TweenInfo.new(0.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {
- Size = UDim2.new(0, 400, 0, 70)
- }):Play()
- RunService.RenderStepped:Connect(function()
- if isLocked and lockedPlayer and lockedPlayer.Character and lockedPlayer.Character:FindFirstChild("HumanoidRootPart") then
- local bodyPosition = lockedPlayer.Character.HumanoidRootPart.Position
- smoothCameraLock(bodyPosition)
- -- Keep the camera locked onto the target's body
- UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
- UserInputService.MouseIconEnabled = true
- end
- end)
- end
- -- Function to unlock the mouse
- local function unlockMouse()
- isLocked = false
- lockedPlayer = nil
- UserInputService.MouseBehavior = Enum.MouseBehavior.Default
- mouse.Icon = "" -- Reset the mouse icon
- StatusText.Text = "Finding player..." -- Update the GUI status
- end
- -- Function to check for players near the mouse pointer
- local function checkForPlayers()
- for _, targetPlayer in pairs(Players:GetPlayers()) do
- if targetPlayer ~= player and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") then
- local targetPosition = targetPlayer.Character.HumanoidRootPart.Position
- local mousePosition = Vector3.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)
- local distance = (targetPosition - mousePosition).Magnitude
- if distance <= lockDistance and targetPlayer ~= lockedPlayer then -- Check if the target is different
- return targetPlayer
- end
- end
- end
- return nil
- end
- -- Function to toggle between locking and unlocking the mouse
- local function toggleLock()
- if isLocked then
- unlockMouse() -- If the mouse is currently locked, unlock it
- else
- local targetPlayer = checkForPlayers() -- Check if there's a player to lock onto
- if targetPlayer then
- lockMouseToPlayer(targetPlayer) -- If a player is found, lock onto them
- end
- end
- end
- -- Listen for the G key to toggle lock/unlock
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.G then
- toggleLock()
- end
- end)
- -- Continuously check if the locked player is killed
- RunService.RenderStepped:Connect(function()
- if isLocked and lockedPlayer and lockedPlayer.Character then
- local humanoid = lockedPlayer.Character:FindFirstChild("Humanoid")
- if humanoid and humanoid.Health <= 0 then
- unlockMouse() -- Unlock the mouse if the opponent is killed
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment