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