Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make bots move to random places?

Asked by 4 years ago

I want bots in my game to move to random places. I tried to do it by placing parts all over the place and scripting this. But it didn't work. Please help, thank you! <3

local pathfindingService = game:GetService("PathfindingService")

local humanoid = script.Parent:WaitForChild("Humanoid")

local torso = script.Parent:WaitForChild("Torso")

local startingPoint = torso.Position
local endingPoints = game.Workspace.EndParts:GetChildren()
local endingPoint = endingPoints[math.random(1, endingPoints)]

local path = pathfindingService:CreatePath()
path:ComputeAsync(torso.Position, endingPoint)

while true do

humanoid:MoveTo(endingPoint)
    wait(1)
end

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

SOLUTION

on line 09 add # before endingPoints

on line 12 add .Position after endingPoints

move ending points to loop

and use for loop

SCRIPTING

local pathfindingService = game:GetService("PathfindingService")

local humanoid = script.Parent:WaitForChild("Humanoid")

local torso = script.Parent:WaitForChild("Torso")

local startingPoint = torso.Position
local endingPoints = game.Workspace.EndParts:GetChildren()

while true do
    local endingPoint = endingPoints[math.random(1, #endingPoints)]
    local path = pathfindingService:CreatePath()
    path:ComputeAsync(torso.Position, endingPoint.Position)

    for _, waypoint in pairs(path:GetWaypoints()) do
        if waypoint.Action == Enum.PathWaypointAction.Jump then
            humanoid.Jump = true
        end
        humanoid:MoveTo(waypoint.Position)
        humanoid.MoveToFinished:Wait()
    end
    wait(1)
end
0
THANK YOU VERY MUCH! YOU SAVED MY LIFE! Inciney 7 — 4y
Ad

Answer this question