I’ve been trying out Pathfinding and it’s working surprisingly well, but when I have tried to make it follow a player it did not work.
Here’s the code:
local PathFindingService = game:GetService("PathfindingService")
local Model = script.Parent
local PointA = workspace.PointA
local Players = game.Players
local human = Model:WaitForChild("Humanoid")
local torso = Model:WaitForChild("Torso")
local path = PathFindingService:CreatePath()
path:ComputeAsync(torso.Position, PointA.Position)
local wayPoints = path:GetWaypoints()
local _dinstace = 0
for i, waypoint in pairs(wayPoints) do
local Part = Instance.new("Part", workspace)
Part.Shape = Enum.PartType.Ball
Part.Material = Enum.Material.Neon
Part.Size = Vector3.new(0.6, 0.6, 0.6)
Part.Anchored = true
Part.CanCollide = false
Part.Position = torso.Position
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
for i, _player in pairs(workspace:GetChildren()) do
if _player:IsA("Model") then
for i, player in pairs(Players:GetChildren()) do
if _player.Name == player.Name then
if _player:FindFirstChild("Humanoid" and "HumanoidRootPart") then
while true do
wait(1)
local dinstace = (torso.Position-_player.HumanoidRootPart.Position).Magnitude
_dinstace = dinstace
task.wait(0.5)
print(_dinstace)
end
end
end
end
end
end