Strange bug related to pathfinding

I have this code:

function generatePath(RP, destination)
	local path = PS:CreatePath(pathParams)

	path:ComputeAsync(RP.Position, destination)

	return path	
end

game.Players.PlayerAdded:Connect(function(plr)
	
	task.wait(2)
	player = plr
	local spotParkedOn = SpawnCar.Park()
	print(spotParkedOn)
	local randNpc = game.ReplicatedStorage.NPCS:FindFirstChild(math.random(1,1))
	randNpc.Parent = game.Workspace
	randNpc.Humanoid.DisplayDistanceType = "None" 
	if randNpc.HumanoidRootPart then
		print("humanoid root exists")
	end
	
	print(spotParkedOn)
	
	--randNpc.HumanoidRootPart.Position = game.Workspace.ParkingSpots:FindFirstChild(spotParkedOn).Position + Vector3.new(0, 20, 0) ( this line is the issue)

	
	task.wait(5)
	
	local path = generatePath(randNpc.HumanoidRootPart, CustomerWalkTo.Position)
	randNpc.HumanoidRootPart:SetNetworkOwner(nil)
	if path.Status == Enum.PathStatus.Success then
		print("pathfinding succesful")
		for i, waypoint in pairs(path:GetWaypoints()) do
			randNpc.Humanoid:MoveTo(waypoint.Position)
			randNpc.Humanoid.MoveToFinished:Wait()
		end
	end
	--]]
	--event:FireClient(player, "Go inside the restaurant", "show")
	--entertedRestaurant()
	
	
	
end)

That one line that I highlighted to be the issue in the code serves one purpose, to set the spawned in AI neared to where a module parks their car, the module works fine and the car is parked as intended. However the following behavior is unexpected if the line is left in, if tagged out however the code works fine.

With the buggy line:

Without the buggy line:

As you can see with that one line the pathfinding breaks entirely and i have no idea why, that is what i need help with. All the line is doing is teleporting the root part before it even starts to pathfinding so I don’t see why it would break anything and why it does so and in such a random way

Bump, I still need someone to help


This is the problem. Whatever you do, do NOT edit the Position property when it comes to moving characters. Use CFrame and CFrame only (or functions that use it under the hood, so Model:PivotTo()).

The cause of such “phenomenon” has been explained by @Judgy_Oreo in a reply under mine.

1 Like

Using .Position does not account for any joints, so everything becomes offset, but .CFrame moves connected parts along with the part you are moving.

2 Likes

I’ve used position in the past to move characters in the past without issue

This line is the direct cause of this issue…


Just move them using the CFrame property and it’ll work well.

1 Like