Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

how do i make a pathfinding system in roblox studio for a npc named: Noobster

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-preview-04-17’s answer.
  1. User

    how do i make a pathfinding system in roblox studio for a npc named: Noobster

  2. Assistant

    Below is a step‐by‐step guide to create a basic pathfinding system for your NPC named Noobster using Roblox’s built-in PathfindingService. This example assumes:

    • You have a model named Noobster located in the Workspace.
    • Noobster has a Humanoid and a PrimaryPart (usually set to the part representing its center).
    • You have a destination (either another part or a defined position) to which you'd like Noobster to navigate.

    Note: This is a basic example. Depending on your game’s needs, you might need to handle edge cases such as when the path isn’t found or when obstacles dynamically change.


    1. Setting Up the NPC

    1. Model Setup:

      • Ensure the Noobster model is in the Workspace.
      • Confirm that Noobster contains a Humanoid and a PrimaryPart.
        (If a PrimaryPart isn’t set, select an appropriate part, right-click on the model in the Explorer, and choose “Set PrimaryPart”.)
    2. Adding a Destination:

      • For testing, you can add a Part to the Workspace (name it Target for instance).
      • Position the Target where you want Noobster to go.

    2. Scripting the Pathfinding

    1. Insert a Script:

      • Insert a Script inside Noobster or in ServerScriptService.
    2. Script Code Example:

    Below is a Lua script example using the PathfindingService:

    -- Obtain the PathfindingService
    local PathfindingService = game:GetService("PathfindingService")
    
    -- Reference Noobster and its components
    local npc = game.Workspace:WaitForChild("Noobster")
    local humanoid = npc:WaitForChild("Humanoid")
    
    -- Ensure Noobster has a PrimaryPart set. If not, you may set it manually as needed.
    if not npc.PrimaryPart then
        warn("Noobster does not have a PrimaryPart set!")
        return
    end
    
    -- Define the destination.
    -- This example assumes there's a part named "Target" in the workspace.
    local targetPart = game.Workspace:WaitForChild("Target")
    local destination = targetPart.Position
    
    -- Create a path object using the default settings.
    local path = PathfindingService:CreatePath({
        AgentRadius = 2,            -- Adjust based on your NPC's size
        AgentHeight = 5,            -- Adjust based on your NPC's height
        AgentCanJump = true,        -- Allow jumping if needed
        AgentJumpHeight = 10,       -- Adjust jump height
        AgentMaxSlope = 45,         -- Maximum slope angle the NPC can traverse
    })
    
    -- Compute the path from Noobster's current position to the destination.
    local startPos = npc.PrimaryPart.Position
    path:ComputeAsync(startPos, destination)
    
    -- Check the status of the computed path
    if path.Status == Enum.PathStatus.Success then
        local waypoints = path:GetWaypoints()
        
        -- Loop through each waypoint to move the NPC
        for _, waypoint in ipairs(waypoints) do
            -- Move to waypoint position
            humanoid:MoveTo(waypoint.Position)
            
            -- Optional: Handle different actions at the waypoint type
            if waypoint.Action == Enum.PathWaypointAction.Jump then
                humanoid.Jump = true
            end
            
            -- Wait until the NPC reaches the waypoint (or time out after a few seconds)
            local reached = humanoid.MoveToFinished:Wait()
            if not reached then
                warn("Failed to reach waypoint at position:", waypoint.Position)
                break
            end
        end
    else
        warn("Path could not be computed. Status:", path.Status)
    end
    

    3. Explanation

    • PathfindingService:
      The script begins by getting the PathfindingService to create and compute a path.

    • Path Creation:
      We define parameters such as AgentRadius and AgentHeight to match the NPC’s collision boundaries and behavior.

    • Computing the Path:
      The ComputeAsync function calculates a path from Noobster’s position to the destination. It then checks if the path was successfully computed with path.Status.

    • Following the Path:
      Once a valid path is found, the script iterates through each waypoint:

      • Uses Humanoid:MoveTo() to command the NPC.
      • Waits for MoveToFinished to ensure the NPC has reached the current waypoint before proceeding.
      • Checks for jump actions if the waypoint indicates to jump.
    • Error Handling:
      The script includes warnings for missing PrimaryPart or if the path fails to compute.


    4. Testing and Troubleshooting

    • Test in Play Mode: Run your game in Roblox Studio to see Noobster move toward the target.
    • Adjust Parameters: Tweak the AgentRadius, AgentHeight, AgentJumpHeight, and AgentMaxSlope based on your NPC’s model for smoother movement.
    • Handling Obstacles: If your game features dynamic obstacles, consider recalculating the path if movement is interrupted.

    By following these steps, you should have a basic, working pathfinding system for Noobster in Roblox Studio. You can expand and refine this system further based on your game design and specific NPC behaviors.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.