the pathfinding script i made (which kinda sucks) just wont work after i added the destDecider function but it worked beforehand, please help and explain what went wrong so i know not to make the same mistake
local PathServ = game:GetService("PathfindingService")
local RunServ = game:GetService("RunService")
local mainStageNode = game.Workspace.PathNodes.Bonnie:WaitForChild("BonMainStage")
local diningRoomNode = game.Workspace.PathNodes.Bonnie:WaitForChild("BonDiningRoom")
local bonnie = script.Parent
local humanoid = bonnie:WaitForChild("Humanoid")
local destinationNode = mainStageNode
local pathfindEnabled = true
local time = 1
local aggression = 20
local path = PathServ:CreatePath()
local success, errorMessage = pcall(function()
local mainStagePath = path:ComputeAsync(bonnie.PrimaryPart.Position, destinationNode.Position)
end)
local function timeDecider()
local timeNumber = math.random(30/aggression, 25-aggression)
time = timeNumber
print(time)
end
local function destDecider()
if destinationNode == mainStageNode then
destinationNode = diningRoomNode
end
print(destinationNode)
end
if success then
timeDecider()
destDecider()
task.wait(time)
for _,destinationNode in pairs(path:GetWaypoints()) do
if pathfindEnabled == false then
print("pathfindEnabled == false")
break
end
print("success")
humanoid:MoveTo(destinationNode.Position)
humanoid.MoveToFinished:Wait()
end
RunServ.Heartbeat:Wait()
else
warn(errorMessage)
end```