So I am trying to make a Piggy-style game, but I do not know how to script the bot to follow the players. I tried using pathfinding service, but then I realized that as the player moves, the route doesn’t recalculate.
So then I tried to recalculate the route after it reaches the waypoint, but it is very laggy. (code is below)
wait(5)
local moveto
local PathfindingService = game:GetService("PathfindingService")
local PlayerToFollowPlayer = game.Players:FindFirstChildOfClass("Player")
local PlayerToFollow = PlayerToFollowPlayer.Character
local MyHumanoid = script.Parent:WaitForChild("Humanoid")
local MyRoot = script.Parent:WaitForChild("HumanoidRootPart")
local path = PathfindingService:CreatePath()
spawn(function()
while true do
path:ComputeAsync(MyRoot.Position, PlayerToFollow.HumanoidRootPart.Position)
points = path:GetWaypoints()
end
end)
wait(1)
while true do
moveto = points[2]
MyHumanoid:MoveTo(moveto.Position)
wait()
end
How should I make the bot chase the players around?