Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make bots move to random places?

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

✓ Accepted answer

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

1 comment

0

THANK YOU VERY MUCH! YOU SAVED MY LIFE!

This discussion is preserved as it was. New answers, comments, and votes are closed.