I’m trying to make a system where when the player clicks a button, a character walks to a brick, get destroyed and adds to the leaderstat, but the AI instead just walks off to the side, besides the fact that it has drawn the route with the neon bricks.
In the image, you can see that there are routes dotted out, but none of them seems to follow it, they just walk against the wall instead
scripts
Pathfinding script
local PathfindingService = game:GetService("PathfindingService")
local Noob = script.Parent.Parent
local Humanoid = script.Parent
local destination = game.Workspace.Destination
local destination2 = game.Workspace.Destination2
local destination3 = game.Workspace.Destination3
local destination4 = game.Workspace.Destination4
local path = PathfindingService:CreatePath()
local randomdest = math.random(1,4)
if randomdest == 1 then
path:ComputeAsync(Noob.Torso.Position, destination.Position)
elseif randomdest == 2 then
path:ComputeAsync(Noob.Torso.Position, destination2.Position)
elseif randomdest == 3 then
path:ComputeAsync(Noob.Torso.Position, destination3.Position)
else
path:ComputeAsync(Noob.Torso.Position, destination4.Position)
end
local waypoints = path:GetWaypoints()
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
-- Move zombie to the next waypoint
Humanoid:MoveTo(waypoint.Position)
-- Wait until zombie has reached the waypoint before continuing
Humanoid.MoveToFinished:Connect(function()
for i,v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Chickens.Value += 1
Noob:Destroy()
end
end)
end