You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
To find a fix for this bug.
What is the issue? Include screenshots / videos if possible!
The zombie’s pathfinding AI randomly breaks and starts going to random positions when it was supposed to walk towards the nearest player and attack them. They instead go to random positions in the map and they all pile up in that one spot.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried visualizing their waypoints to see if it would target me, but their waypoints are also out of place. The final waypoint would be at a completely random position of the map and they would follow that way point. I thought it was the SimplePath module I was using as this module was last updated in 2022 so its pretty outdated, so I tried doing the pathfinding myself but then the same problem still happens.
I have never touched the game prior to this breaking, it just randomly started happening when I was trying to show the game to my friend after not working on the game for so long, and we were both confused as to why the zombies were just walking to random positions instead of chasing us, can someone tell me if this is a Roblox bug or not?
All the zombies are being controlled by one script in ServerScriptService using CollectionService and it has been working flawlessly ever since I started working on the game which was probably a year ago, and now when I come back to it the pathfinding just randomly broke.
Here’s the bug in action (Happens at around 0:30):
UPDATE: I tried printing the final waypoint of each path computation and printing the actual destination it’s supposed to go to so I can see the difference with each Vector3’s
Heres the position’s it printed (You can also see the zombies piling up right in front of me instead of chasing me, of course because their pathfinding is broken):
Heres a closer look, you can clearly see that theres a BIG difference with the Z values on the final waypoint’s position and the actual position it’s supposed to go to:
On the final waypoint, the Z value is -64
But when you take the position it’s supposed to go to, the Z value is actually -83.235…
From what I see in the video, the waypoints simply never refresh until the zombie walks to the previous destination. You can fix that by constantly refreshing the path.
Also without the script itself we can’t fully help you.
local module = {
Move = function(Humanoid : Humanoid, StartingPosition : Vector3, DestinationPosition : Vector3, Visualize : boolean, PathfindingAgents : {}, DitchComputingDistance : number, TimeVariance : number)
if DitchComputingDistance == nil then
DitchComputingDistance = 10
end
if TimeVariance == nil then
TimeVariance = 0.5
end
if PathfindingAgents == {} then
PathfindingAgents = {
AgentCanJump = true,
AgentRadius = 2.5,
AgentHeight = 2.5,
AgentCanClimb = true
}
end
local PathfindingService = game:GetService("PathfindingService")
local Path = PathfindingService:CreatePath(PathfindingAgents)
local waypoints
local nextWaypointIndex
local computed = false
local function followPath(destination : Vector3)
local success, errorMessage = pcall(function()
Path:ComputeAsync(StartingPosition, destination)
end)
Humanoid:SetAttribute("PATHFINDING",false)
local interrupted = false
Humanoid:SetAttribute("PATHFINDING",true)
local attCon
attCon = Humanoid.AttributeChanged:Connect(function()
if not Humanoid:GetAttribute("PATHFINDING") then
interrupted = true
attCon:Disconnect()
end
end)
if success and Path.Status == Enum.PathStatus.Success then
waypoints = Path:GetWaypoints()
print(waypoints[#waypoints].Position)
print("WHAT PATHFINDING THINKS")
print(destination)
print("WHERE IT'S SUPPOSED TO GO")
nextWaypointIndex = 0
local done = false
if Visualize == true then
print("VISUALIZING PATH")
task.spawn(function()
for i, waypoint in ipairs(waypoints) do
local pointBall = Instance.new("Part")
pointBall.Size = Vector3.new(1,1,1)*0.5
pointBall.Anchored = true
pointBall.CanCollide = false
pointBall.CanTouch = false
pointBall.CanQuery = false
pointBall.Position = waypoint.Position
pointBall.Color = Color3.new(1,1,1)
pointBall.Shape = Enum.PartType.Ball
pointBall.Material = Enum.Material.Neon
pointBall.Name = "VisualizerWaypoint"
pointBall.Parent = workspace
task.spawn(function()
local repLimit = 120
local currentRep = 0
repeat
local dt = task.wait()
currentRep += dt
until nextWaypointIndex >= i or currentRep >= repLimit or done or interrupted
pointBall:Destroy()
end)
end
end)
end
for i, waypoint in ipairs(waypoints) do
if i > 1 then
if not interrupted then
Humanoid:MoveTo(waypoint.Position)
else
break
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid.MoveToFinished:Wait()
end
nextWaypointIndex += 1
end
done = true
Humanoid:SetAttribute("PATHFINDING",nil)
end
end
local distance = (DestinationPosition - StartingPosition).Magnitude
if distance > DitchComputingDistance then
task.spawn(function()
followPath(DestinationPosition)
end)
task.wait(TimeVariance)
computed = true
else
Humanoid:MoveTo(DestinationPosition)
end
return computed
end,
Stop = function(Humanoid : Humanoid)
Humanoid:SetAttribute("PATHFINDING",nil)
end,
}
return module
It’s my first time using PathfindingService here without using a pre-made module like SimplePath so there might be some mistakes you’ll find here
The thing is the reason why I made this is because I thought the bug was coming from the SimplePath module itself but I was wrong, this one worked just fine on my other newer game though but not on this game, the same problem happens for this game even if I’m using SimplePath or the new one I just made