Nah I don’t believe this to be it. It seems to be something happening on my end more than ROBLOX’s because other projects have seem to run fine? This crashing happens consistently
Check your script activity on the devconsole and log what scripts are active then work from there. Start isolating code and logging what connections are open/closed manually. It’s going to be rough work because there’s no easy fix/way to find memory leaks. And remember to close connections when they are no longer needed
Narrowed the issue down to pathfinding it ONLY happens when my AIs have pathfinding enabled and it doesn’t show any activity prior it just ups and spikes as shown:
How many NPCs are you spawning in? I can easily have several hundred and see no noticable lag at all. Have you considered using an NPC system like Justice the Awesome NPC system:
Fair point, but you can spawn R15 rigs instead via some simple changes. Alternatively would you care to share the relevant npc spawn & control code so we can review it.
task.spawn(function()
while not workspace:GetAttribute("PathfindCancel") do
task.wait((#Battles - 1)*0.1 + 0.2)
ActiveRequest = ActiveRequest
ComputationQueue = ComputationQueue
if #Battles == 0 then continue end
local EarliestID
local EarliestInfo
local PreviousTime
for ID,Info in pairs(ComputationQueue) do
if not (Info.Request and Info.QueueTime) then continue end
task.wait(0.1)
if not PreviousTime then
EarliestID = ID
EarliestInfo = Info
PreviousTime = Info.QueueTime
elseif (tick() - PreviousTime) < (tick() - Info.QueueTime) then
EarliestID = ID
EarliestInfo = Info
PreviousTime = Info.QueueTime
end
end
if EarliestID and ComputationQueue[EarliestID] and (tick() - LastCompute) >= 2 then
warn("Computing "..(tick() - LastCompute))
LastCompute = tick()
local Index = ComputationQueue[EarliestID] or {}
local Path = PathfindingService:CreatePath(Index.Params or {})
Path:ComputeAsync(Index.StartPos,Index.GoalPos)
if Path.Status == Enum.PathStatus.Success then
ComputationQueue[EarliestID] = {Path=Path}
else
if Path then Path:Destroy() end
local Attempts = Index.Attempts or 0
Attempts += 1
if Attempts > 2 then
ComputationQueue[EarliestID].Request = nil
elseif ComputationQueue[EarliestID] and ComputationQueue[EarliestID].Attempts then
ComputationQueue[EarliestID].Attempts = Attempts
end
end
end
end
end)
local SpawnCF = Data.SpawnCF
local CHSpawn = SpawnFolder:GetChildren()[math.random(1,#SpawnFolder:GetChildren())]
if (CHSpawn or SpawnCF) then
local Model
if IsPlayer and SquadCount == 1 and (Controller and Controller.Parent) then
local BattleHUD = Assets.GUI.Battle.BattleHUD:Clone()
BattleHUD.Parent = Controller.PlayerGui
end
Model = AceData.ModelRef or Data.Model
if not Model then
local FolderIndex = ReplicatedStorage.Assets.CharacterModels.Skins
Model = AceData.ActiveSkin and FolderIndex and FolderIndex:FindFirstChild(AceData.ActiveSkin) or ReplicatedStorage.Assets.CharacterModels:FindFirstChild(AceName)
if not Model then
warn("No model found for "..AceName)
AceFolder:Destroy()
return
end
Model = Model:Clone()
end
if not Model then
Model = Assets.ReferenceRig:Clone()
end
local HUM = Model:FindFirstChild("Humanoid")
HUM.RequiresNeck = false
HUM.AutoJumpEnabled = false
if SquadCount == 1 and not Data.SpawnCF then
StartPos[Team] = (CHSpawn.CFrame)
SpawnCF = StartPos[Team]
table.insert(SpawnPositions[Team], SquadCount, SpawnCF)
local FullCircle = (2 * math.pi)
local Dist = 12
for i = 2, MaxSquad do
local Angle = -(i * (FullCircle/MaxSquad))
local x = math.cos(Angle) * Dist
local z = math.sin(Angle) * Dist
local AdditionalSpawnCF = StartPos[Team] * CFrame.new(x, 0, z)
table.insert(SpawnPositions[Team], i, AdditionalSpawnCF)
end
elseif not Data.SpawnCF then
local TeamSpawns = SpawnPositions[Team]
SpawnCF = TeamSpawns[SquadCount]
end
local FinalSpawnCF = SpawnCF or StartPos[Team] or (CHSpawn.CFrame)
Model.PrimaryPart.CFrame = FinalSpawnCF--*CFrame.new(0,-2,0)
local BG = Instance.new("BodyGyro",Model.PrimaryPart)
BG.CFrame = FinalSpawnCF
BG.MaxTorque = Vector3.new(1e8,1e8,1e8)
game.Debris:AddItem(BG,1.5)
Model.Name = "Model"
Model.Parent = AceFolder
local Container
if not Data.Model then -- Creates a new container and makes a state connection if its a brand new model
Container = StateHandler:GetContainer(HUM) or StateHandler:CreateContainer(HUM)
local StateConnection = Container.StateAdded.Event:Connect(StatusAdded)
local StateConnection2 = Container.StateRemoved.Event:Connect(StatusRemoved)
table.insert(BattleConnections,StateConnection)
table.insert(BattleConnections,StateConnection2)
local StateConnected3 = HUM.StateChanged:Connect(function()
local NewState = HUM:GetState()
if table.find(BadStates,NewState) then
HUM:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end)
table.insert(BattleConnections,StateConnected3)
else
Container = StateHandler:GetContainer(HUM) or StateHandler:CreateContainer(HUM)
end
if not table.find(ActiveAces,AceFolder) then
table.insert(ActiveAces, AceFolder)
end
Alright I believed I resolved the issue: In my game battles are created further and further away from the origin so eventually computing a path 342432342342334 studs away gets a bit hectic for the pathfinding causing the server to crash