This is a Bug Report
While working on a new project for ROBLOX, I’ve decided to make a new Chase Script for my NPCs, in which I scripted a reformed pathfinding script. While testing on the game’s publish, I notice that the game would crash on random frequencies: sometimes early (less than a minute), and sometimes later (the longest encounter was almost an hour).
I’ve looked through my script to see if there was some ridiculous/endless loops that were causing the servers to immediately die, but from what I’ve seen, I haven’t seen any of such.
I noticed the last time the server crash, a NPC attacked an NPC that was pathfinding to it’s target, maybe this can help? I will also post the pathfinding script’s code here. Note that each NPC has a script containing this.
Game Link: [Weapon Test] Noobs vs Zombies Tycoon 2 - Roblox
Place Link: [Weapon Test] Noobs vs Zombies Tycoon 2 - Roblox
Edit: Issue still happens.
Edit #2: After commenting the pathfinding portion of the Chase Script, servers never crash anymore. This only reinforces my theory that the pathfinding service is most likely causing the crashes, and not the chase script itself.
Edit #3: I was able to fix this issue by having a different event control how frequently the pathfinding service can be called, and doing so helped fixed the servers from crashing.
--[[
local GeneratedPath = PathfindingService:CreatePath({AgentRadius = 2, AgentHeight = 5})
GeneratedPath:ComputeAsync(Torso.Position, Target.Position)
if GeneratedPath.Status == Enum.PathStatus.Success then
local WayPoints = GeneratedPath:GetWaypoints()
local MoveToConnection
local BlockConnection
local TargetPathSpot = Target.Position
local PathEnded = false
local MaxTimeOnNod = (1.15 / (Humanoid.WalkSpeed/16))
local function OnPathBlock()
PathEnded = true
end
BlockConnection = GeneratedPath.Blocked:Connect(OnPathBlock)
local TimeOnWaypoint = tick()
local CurrentNode = 0
local HealthOnPathfind = Humanoid.Health
for i = 1, #WayPoints, 3 do
CurrentNode = i
TimeOnWaypoint = tick()
local waypoint = WayPoints[i]
TargetSpotted = AttemptToLookAtTarget(TargetCharacter, TargetHead)
if PathEnded == true then break end
if (TargetPathSpot-Target.Position).magnitude >= 80 then break end
if (Torso.Position-Target.Position).magnitude <= 5 then break end
if Humanoid.Health <= HealthOnPathfind*0.975 then break end
if TargetSpotted == true then break end
Humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
delay(0, function()
local CurrentTime = 0
while CurrentNode == i and CurrentTime < MaxTimeOnNod do
CurrentTime = (tick()-TimeOnWaypoint)
wait(0.15)
end
if CurrentTime >= MaxTimeOnNod and CurrentNode == i then print("Path Broke") PathEnded = true end
end)
Humanoid.MoveToFinished:Wait()
end
if BlockConnection then BlockConnection:Disconnect() end
if MoveToConnection then MoveToConnection:Disconnect() end
elseif GeneratedPath.Status ~= Enum.PathStatus.Success then
-- > print("Path Generated is not successful :(")
Humanoid:MoveTo(Target.Position)
table.insert(FilteredTargets, #FilteredTargets+1, TargetCharacter)
local TargetOnList = TargetCharacter
delay(15, function()
for i = 1, #FilteredTargets do
if FilteredTargets[i] == TargetOnList then
table.remove(FilteredTargets, i)
end
end
end)
end
if GeneratedPath then GeneratedPath:Destroy() end
--]]