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!
I want to make a pathfinding bank with spawning/despawning civils on the streets. -
What is the issue? Include screenshots / videos if possible!
After some time, the output slaps me with:
Workspace.NPCs.Civils.Civilian.Pathfind_Civilian:61: stack overflow
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
No, I didn’t. I don’t think I would find anything there though.
–
So it errors at a pathfinding script in ServerScriptService, which looks like this:
I put the entire script in here
It errors on line 61, which is an if statement
local dummy = script.Parent
dummy.PrimaryPart:SetNetworkOwner(nil)
local PathFinding = game:GetService("PathfindingService")
local lastWaypoint = nil
local onBreak = false
local agentParams = {
["AgentHeight"] = 5,
["AgentRadius"] = 5,
["AgentCanJump"] = false
}
local function createPath(destination : BasePart)
local path = PathFinding:CreatePath(agentParams)
path:ComputeAsync(dummy.HumanoidRootPart.Position, destination.Position)
return path
end
local function moveTo(target : BasePart)
local path = createPath(target)
for i, obj in pairs(workspace:GetDescendants()) do
if obj:IsA("Seat") then
if obj.Occupant == dummy.Humanoid then
obj:Sit(nil)
task.wait(0.1)
dummy.PrimaryPart.CFrame = obj.Waypoint.Value.CFrame + Vector3.new(0, 2, 0)
end
end
end
for i, waypoint in pairs(path:GetWaypoints()) do
dummy.Humanoid:MoveTo(waypoint.Position)
dummy.Humanoid.MoveToFinished:Wait()
end
if target.Name == "SeatWaypoint" then
task.wait(0.1)
target.Seat.Value:Sit(dummy.Humanoid)
end
game:GetService("TweenService"):Create(dummy.HumanoidRootPart, TweenInfo.new(0.2),
{CFrame = target.CFrame + Vector3.new(0, 2, 0)}):Play()
if target.Name == "DespawnWaypoint" then
target:SetAttribute("Occupied", false)
game.ReplicatedStorage.DespawnTouched:Fire(dummy)
end
end
local function randomize(location : Folder)
local waypoints
if #location:GetChildren() ~= 0 then -- the line the output tells me
waypoints = location:GetChildren()
else
warn("Location does not have any waypoints")
end
local goal = waypoints[math.random(1, #waypoints)]
if goal:GetAttribute("Occupied") == false and goal ~= lastWaypoint then
for i, point in pairs(waypoints) do
point:SetAttribute("Occupied", false)
end
goal:SetAttribute("Occupied", true)
return goal
else
return randomize(workspace.Waypoints_Civil.CivilianWaypoints)
end
end
local goal = randomize(workspace.Waypoints_Civil.CivilianWaypoints)
moveTo(goal)
lastWaypoint = goal
task.wait(5)
while wait() do
task.wait(math.random(3, 5))
local goal = randomize(workspace.Waypoints_Civil.CivilianWaypoints)
moveTo(goal)
end
This code shows the newer script, because it overflowed on a GetChildren() function before. I absolutely have no idea how could this happen. Thanks in advance!