How Do You Make A Piggy Bot?

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?

1 Like

I found this free model.

The pathfinding it uses allows it to follow you without them trying to get through walls.

There’s about 5 bots included in this model, so I deleted 4 of them, left one, put a bunch of random walls, and tested it.

Looks through the scripts, and they’ll probably explain to your how they work.

https://www.roblox.com/library/4867946854/Piggy-PathFinding-Model-Updated-Updated

3 Likes