-- Services and Variables local players = game:GetService("Players") local user = players.LocalPlayer local runService = game:GetService("RunService") local virtualInput = game:GetService("VirtualInputManager") -- For simulating key presses local mouse = user:GetMouse() local function shuffleTable(tbl) local n = #tbl for i = n, 2, -1 do local j = math.random(i) tbl[i], tbl[j] = tbl[j], tbl[i] -- Swap elements end end -- UI Setup local ScreenGui = Instance.new("ScreenGui", user.PlayerGui) local ToggleButton = Instance.new("TextButton") local StatusLabel = Instance.new("TextLabel") ScreenGui.Name = "AFKBotUI" ScreenGui.ResetOnSpawn = false -- Button Styling ToggleButton.Name = "ToggleButton" ToggleButton.Size = UDim2.new(0, 200, 0, 50) ToggleButton.Position = UDim2.new(0.5, -100, 0.1, 0) ToggleButton.Text = "Turn ON Bot" ToggleButton.Parent = ScreenGui -- Status Label Styling StatusLabel.Name = "StatusLabel" StatusLabel.Size = UDim2.new(0, 200, 0, 25) StatusLabel.Position = UDim2.new(0.5, -100, 0.16, 0) StatusLabel.Text = "Status: OFF" StatusLabel.TextColor3 = Color3.new(1, 0, 0) StatusLabel.Parent = ScreenGui -- Bot Logic Variables local isBotActive = false local targetModel = nil local lastTargetPosition = nil local runAwayTime = 3 -- Time to run away if a move is detected -- Function to Pick a Target local function pickTarget() StatusLabel.Text = "Status: Click a character (player/NPC) to target!" local target = nil local connection connection = mouse.Button1Down:Connect(function() local obj = mouse.Target if obj then local model = obj:FindFirstAncestorOfClass("Model") if model and model:FindFirstChild("Humanoid") and model:FindFirstChild("HumanoidRootPart") then target = model StatusLabel.Text = "Status: Target set - " .. target.Name connection:Disconnect() end end end) while target == nil and isBotActive do task.wait() end return target end -- Move and Face Target local function moveToTarget() local character = user.Character or user.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local rootPart = character:WaitForChild("HumanoidRootPart") while isBotActive do -- Pick a new target if there isn't one if not targetModel then targetModel = pickTarget() lastTargetPosition = nil end if targetModel then local targetRoot = targetModel:FindFirstChild("HumanoidRootPart") if not targetRoot then targetModel = nil -- Reset if target is invalid continue end local targetPosition = targetRoot.Position local distanceToTarget = (rootPart.Position - targetPosition).Magnitude -- Check if the target is holding a tool local targetHumanoid = targetModel:FindFirstChild("Humanoid") local toolHeld = false for _, child in ipairs(targetModel:GetChildren()) do if child:IsA("Tool") then toolHeld = true break end end -- Run away if the target is holding a tool or using a move if toolHeld then StatusLabel.Text = "Status: Running Away!" local oppositeDirection = rootPart.Position + (rootPart.Position - targetPosition).Unit * 10 humanoid:MoveTo(oppositeDirection) task.wait(runAwayTime) continue end -- Move towards the target if no tool is held humanoid:MoveTo(targetPosition) workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position, targetPosition) -- Recalculate movement if the target moves 6 studs if lastTargetPosition == nil or (lastTargetPosition - targetPosition).Magnitude > 7 then lastTargetPosition = targetPosition end -- Simulate "run" if target is far away if distanceToTarget > 50 then virtualInput:SendKeyEvent(true, Enum.KeyCode.Q, false, nil) wait() virtualInput:SendKeyEvent(false, Enum.KeyCode.Q, false, nil) end -- Check if close enough to target if distanceToTarget < 8 then StatusLabel.Text = "Status: Target Reached!" -- 25% chance to click LMB 4 times if math.random(1,100) <= 50 then for _ = 1, 4 do virtualInput:SendMouseButtonEvent(0, 0, 0, true, nil, false) virtualInput:SendMouseButtonEvent(0, 0, 0, false, nil, false) wait(0.2) end end -- Use a random tool local backpack = user.Backpack local tools = {} -- Filter only valid tools for the bot's use for _, tool in ipairs(backpack:GetChildren()) do if tool:IsA("Tool") then table.insert(tools, tool) tool.Parent=backpack end end -- Check if there are valid tools to choose from if #tools > 0 then for i=1, math.random(10,100) do shuffleTable(tools) end for _, tool in ipairs(tools) do tool.Parent=user.Character tool:Activate() tool.Parent=backpack end end end end -- 1-frame wait before stopping the G key press virtualInput:SendKeyEvent(true, Enum.KeyCode.G, false, nil) wait() -- 1-frame wait here virtualInput:SendKeyEvent(false, Enum.KeyCode.G, false, nil) end end -- Toggle Bot Functionality ToggleButton.MouseButton1Click:Connect(function() if not isBotActive then -- Turn ON Bot ToggleButton.Text = "Turn OFF Bot" StatusLabel.Text = "Status: ON" StatusLabel.TextColor3 = Color3.new(0, 1, 0) isBotActive = true task.spawn(moveToTarget) else -- Turn OFF Bot ToggleButton.Text = "Turn ON Bot" StatusLabel.Text = "Status: OFF" StatusLabel.TextColor3 = Color3.new(1, 0, 0) isBotActive = false targetModel = nil end end)