Pathfinding breaks if cloned and put in workspace

Hey.
My friend and i fixed and advanced a load of things with my pathfinding AI used in my game.
However, we have discovered a issue that when it gets cloned and put in workspace, it becomes braindead. Instead of going around the trees and buildings, the AI turns its back towards it until it tries to jump over it, making it function again until the player goes behind another tree / building, and process repeat until player goes out in the open.

However, if i put it in workspace from the start, the pathfinding will function perfectly and it will have no problems.

I’ve tried putting it from Lighting to ServerStorage, which doesn’t work, and now it is located in ReplicatedStorage. Please note that leaving it in workspace will BREAK the game, as it’s round based and you’re supposed to survive the AI when the round begins.

The part of the script for cloning the AI and putting it in workspace.

     local demon = game.ReplicatedStorage.DemonAI:Clone()

wait(15)
	demon.Parent = game.workspace
	workspace.Soundtrack.NightBeat1:Play()
	workspace.Soundtrack.NightBeat:Play()
Night()

workspace.Soundtrack.NightTimeSong:Play()


demon.AI.Disabled = false
demon.AI.Disabled = true
wait(5)
demon.Stun.Disabled = false
demon.AI.Disabled = false
1 Like

When Pathfinding goes wrong, I tend to force it to display a part to show exactly how it has computed the path. Add the following loop in after you have done the GetWaypoints.

For exmaple::

waypoints = path:GetWaypoints() -- but your version of it

for _, waypoint in pairs(points) do
	local part = Instance.new("Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.BrickColor = BrickColor.new(0.8,0.2,0.8)
	part.Size = Vector3.new(0.6, 0.6, 0.6)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace
end