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
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