Objects deleting being deleted from workspace after a getting a random descendant

I have a script where if there are no targets present then the AI will use the Pathfinding Service to get the children of a folder with markers and their positions to randomly roam a maze.

After one loop the Nodes delete themselves in workspace.

Here is the loop, the LoS and no other part of the script even mentions the Nodes.

Unless I am missing a Nodes = nil or something I do not know why it is deleting the nodes and not the folder even and would appreciate some help :slight_smile: .

local Nodes = game.Workspace:WaitForChild("Nodes"):GetChildren()

function main()
	
	local isChangingDestination = false
	local db = false
	local waypoints
	local count = 1
	
	path:ComputeAsync(enemy.HumanoidRootPart.Position, (Nodes[math.random(1,#Nodes)]).Position)
	waypoints = path:GetWaypoints()
	enemy.Humanoid:MoveTo(waypoints[count].Position)
	isChangingDestination = true
	
	while true do
		local selectedTarget = losCheck()
			
		if selectedTarget then
			isTargeting = true
			isChangingDestination = false
			enemy.Humanoid:MoveTo(players:FindFirstChild(selectedTarget).Character.HumanoidRootPart.Position)
		end
		
		enemy.Humanoid.MoveToFinished:Connect(function()
			if isTargeting and not isChangingDestination and not db then
				print("changing destination")
				isChangingDestination = true
				isTargeting = false
				db = true
				count = 1
				
				local selectedNode = Nodes[math.random(1,#Nodes)]
				path:ComputeAsync(enemy.HumanoidRootPart.Position, selectedNode.Position)
				waypoints = path:GetWaypoints()
				enemy.Humanoid:MoveTo(waypoints[count].Position)
			elseif not isTargeting and isChangingDestination and not db then
				count+=1
				db = true
				if waypoints[count] ~= nil then
					enemy.Humanoid:MoveTo(waypoints[count].Position)
					print("following track")
				else
					print("changing destination once finished")
					count = 1
					local selectedNode = Nodes[math.random(1,#Nodes)]
					path:ComputeAsync(enemy.HumanoidRootPart.Position, selectedNode.Position)
					waypoints = path:GetWaypoints()
					enemy.Humanoid:MoveTo(waypoints[count].Position)
				end
			end
		end)

		db = false
		wait()
	end
end

I have also tried making the parts rest in workspace and getting its descendants but it didn’t work.

solved had to replace the nodes.