Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script to run in an executor
- -- Create the ScreenGui and TextButton if they don't already exist
- local player = game.Players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- -- Create ScreenGui if it doesn't exist
- local screenGui = playerGui:FindFirstChild("CustomScreenGui")
- if not screenGui then
- screenGui = Instance.new("ScreenGui")
- screenGui.Name = "CustomScreenGui"
- screenGui.Parent = playerGui
- end
- -- Create the aim-lock button if it doesn't exist
- local button = screenGui:FindFirstChild("ToggleButton")
- if not button then
- button = Instance.new("TextButton")
- button.Name = "ToggleButton"
- button.Size = UDim2.new(0, 200, 0, 50)
- button.Position = UDim2.new(0.5, -100, 0.5, -25)
- button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Text = "Off"
- button.Parent = screenGui
- end
- -- Draggable functionality
- local dragging = false
- local dragInput, startPos, startPosAbs
- local function onDragBegin(input)
- dragging = true
- startPos = input.Position
- startPosAbs = button.Position
- input.Changed:Connect(function()
- if input.UserInputState == Enum.UserInputState.End then
- dragging = false
- end
- end)
- end
- local function onDrag(input)
- if dragging then
- local delta = input.Position - startPos
- button.Position = UDim2.new(startPosAbs.X.Scale, startPosAbs.X.Offset + delta.X, startPosAbs.Y.Scale, startPosAbs.Y.Offset + delta.Y)
- end
- end
- -- Handle mouse and touch inputs
- button.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- onDragBegin(input)
- end
- end)
- button.InputChanged:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
- onDrag(input)
- end
- end)
- -- Button states
- local isOn = false
- local aiming = false
- -- Function to update the aiming button text and color
- local function updateButtonText()
- if isOn then
- button.Text = "On"
- button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
- aiming = true
- -- Start aiming loop
- spawn(function()
- while aiming do
- local nearestPlayer = nil
- local shortestDistance = math.huge
- for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
- if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
- local distance = (player.Character.HumanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- nearestPlayer = otherPlayer
- end
- end
- end
- if nearestPlayer and nearestPlayer.Character and nearestPlayer.Character:FindFirstChild("HumanoidRootPart") then
- local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position
- local camera = workspace.CurrentCamera
- -- Default aim-lock behavior
- camera.CFrame = CFrame.lookAt(camera.CFrame.Position, targetPosition)
- end
- wait(0.1) -- Update every 0.1 seconds
- end
- end)
- else
- button.Text = "Off"
- button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
- aiming = false
- end
- end
- -- Toggle aiming button state when clicked
- button.MouseButton1Click:Connect(function()
- isOn = not isOn
- updateButtonText()
- end)
- -- Initial button text update
- updateButtonText()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement