-- LocalScript in StarterGui local Players = game:GetService("Players") local PathfindingService = game:GetService("PathfindingService") local UserInputService = game:GetService("UserInputService") local Workspace = game:GetService("Workspace") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local rootPart = character:WaitForChild("HumanoidRootPart") -- Find killbricks (assume parts named "Killbrick") local killbricks = {} for _, part in ipairs(Workspace:GetDescendants()) do if part:IsA("BasePart") and part.Name == "Killbrick" then table.insert(killbricks, part) -- Add PathfindingModifier if not present local modifier = part:FindFirstChildOfClass("PathfindingModifier") if not modifier then modifier = Instance.new("PathfindingModifier") modifier.CostsMultiplier = 10 -- High cost to prefer avoidance modifier.Parent = part end end end -- Create GUI local screenGui = Instance.new("ScreenGui") screenGui.Name = "AIToggleGui" screenGui.Parent = player:WaitForChild("PlayerGui") local toggleButton = Instance.new("TextButton") toggleButton.Name = "ToggleButton" toggleButton.Size = UDim2.new(0, 150, 0, 50) toggleButton.Position = UDim2.new(0.5, -75, 0.8, 0) -- Adjusted position toggleButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255) toggleButton.Text = "Toggle AI: Off" toggleButton.TextSize = 18 toggleButton.Draggable = true toggleButton.Active = true toggleButton.Parent = screenGui local clickButton = Instance.new("TextButton") clickButton.Name = "ClickModeButton" clickButton.Size = UDim2.new(0, 150, 0, 50) clickButton.Position = UDim2.new(0.5, -75, 0.85, 0) -- Underneath clickButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255) clickButton.Text = "Click Mode: Off" clickButton.TextSize = 18 clickButton.Draggable = true clickButton.Active = true clickButton.Parent = screenGui local aiActive = false local clickActive = false local aiCoroutine = nil local visualParts = {} -- Table to hold visual blocks -- Function to clear visual blocks local function clearVisuals() for _, part in ipairs(visualParts) do part:Destroy() end visualParts = {} end -- Function to visualize the path with green blocks local function visualizePath(waypoints) clearVisuals() -- Clear previous visuals for i = 2, #waypoints do -- Start from second waypoint local wp = waypoints[i] local part = Instance.new("Part") part.Size = Vector3.new(0.5, 0.5, 0.5) part.Color = Color3.fromRGB(0, 255, 0) part.Transparency = 0.5 part.Anchored = true part.CanCollide = false part.Position = wp.Position + Vector3.new(0, 0.25, 0) -- Slightly above ground part.Parent = Workspace table.insert(visualParts, part) if wp.Action == Enum.PathWaypointAction.Jump then part.Color = Color3.fromRGB(255, 255, 0) -- Yellow for jump points end end end -- Function to check if position is on a killbrick local function isOnKillbrick(pos) local params = RaycastParams.new() params.FilterDescendantsInstances = killbricks params.FilterType = Enum.RaycastFilterType.Include local result = Workspace:Raycast(pos + Vector3.new(0, 3, 0), Vector3.new(0, -5, 0), params) return result \~= nil end -- Function to check if point is safe (not near edge with >15 stud drop) local function isSafePoint(pos) local safe = true for i = 0, 7 do local angle = i * (2 * math.pi / 8) local offset = Vector3.new(math.cos(angle), 0, math.sin(angle)) * 2 -- 2 studs around local checkPos = pos + offset + Vector3.new(0, 5, 0) local params = RaycastParams.new() params.FilterDescendantsInstances = {character} params.FilterType = Enum.RaycastFilterType.Exclude local result = Workspace:Raycast(checkPos, Vector3.new(0, -20, 0), params) if result then local drop = checkPos.Y - result.Position.Y if drop > 15 then safe = false break end else safe = false break end end return safe end -- Function to get a random navigable point within a radius local function getRandomPoint(center, radius) for _ = 1, 20 do -- Increased tries local angle = math.random() * 2 * math.pi local dist = math.random() * radius local offset = Vector3.new(math.cos(angle) * dist, 0, math.sin(angle) * dist) local goal = center + offset -- Check if there's a path to the goal local path = PathfindingService:CreatePath() path:ComputeAsync(center, goal) if path.Status == Enum.PathStatus.Success and isSafePoint(goal) then return goal end end return nil -- No valid point found end -- Function to move along path with handling for killbricks and jumps local function moveAlongPath(waypoints) local i = 1 while i <= #waypoints do if not aiActive then humanoid:MoveTo(rootPart.Position) break end local wp = waypoints[i] if isOnKillbrick(wp.Position) then -- Find end of kill sequence local startKill = i local endKill = i local killLength = 0 while endKill <= #waypoints and isOnKillbrick(waypoints[endKill].Position) do if endKill > startKill then killLength = killLength + (waypoints[endKill].Position - waypoints[endKill - 1].Position).Magnitude end endKill = endKill + 1 end if endKill > #waypoints then -- All remaining are kill, stop break end local maxJumpDist = 10 -- Adjust based on jump power if killLength <= maxJumpDist then -- Jump over to endKill humanoid.Jump = true humanoid:MoveTo(waypoints[endKill].Position) humanoid.MoveToFinished:Wait(3) i = endKill + 1 else -- Too long, try rerouting with impassable local originalMultipliers = {} for _, kb in ipairs(killbricks) do local mod = kb:FindFirstChildOfClass("PathfindingModifier") if mod then originalMultipliers[kb] = mod.CostsMultiplier mod.CostsMultiplier = math.huge -- Effectively impassable end end -- Recompute from current position to goal local currentPos = rootPart.Position local goal = waypoints[#waypoints].Position local path = PathfindingService:CreatePath() path:ComputeAsync(currentPos, goal) -- Restore for kb, mult in pairs(originalMultipliers) do kb:FindFirstChildOfClass("PathfindingModifier").CostsMultiplier = mult end if path.Status == Enum.PathStatus.Success then waypoints = path:GetWaypoints() visualizePath(waypoints) i = 1 -- Restart with new path continue else -- No alternative, proceed cautiously or stop print("No safe path around killbrick, proceeding with risk") humanoid:MoveTo(wp.Position) if wp.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end humanoid.MoveToFinished:Wait(2) i = i + 1 end end else humanoid:MoveTo(wp.Position) if wp.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end humanoid.MoveToFinished:Wait(2) i = i + 1 end end clearVisuals() end -- AI loop function for random movement local function runAI() while aiActive do local start = rootPart.Position local goal = getRandomPoint(start, 50) -- Adjust radius as needed if goal then local path = PathfindingService:CreatePath() path:ComputeAsync(start, goal) if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() visualizePath(waypoints) moveAlongPath(waypoints) end end wait(1) -- Small delay before next path end end -- Toggle button click handler toggleButton.MouseButton1Click:Connect(function() aiActive = not aiActive toggleButton.Text = "Toggle AI: " .. (aiActive and "On" or "Off") toggleButton.BackgroundColor3 = aiActive and Color3.fromRGB(0, 255, 0) or Color3.fromRGB(255, 255, 255) if aiActive then if aiCoroutine then coroutine.close(aiCoroutine) end aiCoroutine = coroutine.create(runAI) coroutine.resume(aiCoroutine) else clearVisuals() end end) -- Click mode toggle handler clickButton.MouseButton1Click:Connect(function() clickActive = not clickActive clickButton.Text = "Click Mode: " .. (clickActive and "On" or "Off") clickButton.BackgroundColor3 = clickActive and Color3.fromRGB(0, 255, 255) or Color3.fromRGB(255, 255, 255) end) -- Handle clicks for click mode UserInputService.InputBegan:Connect(function(input, gameProcessed) if aiActive and clickActive and not gameProcessed and input.UserInputType == Enum.UserInputType.MouseButton1 then local mouse = player:GetMouse() local goal = mouse.Hit.Position local start = rootPart.Position local path = PathfindingService:CreatePath() path:ComputeAsync(start, goal) if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() visualizePath(waypoints) moveAlongPath(waypoints) end end end) -- Handle character respawn player.CharacterAdded:Connect(function(newChar) character = newChar humanoid = character:WaitForChild("Humanoid") rootPart = character:WaitForChild("HumanoidRootPart") aiActive = false clickActive = false toggleButton.Text = "Toggle AI: Off" toggleButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255) clickButton.Text = "Click Mode: Off" clickButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255) clearVisuals() end)