So I made this script to enchant my original npc following script (Because the original one would just go on a strait line
But It appears to not follow the player
local NPC = script.Parent --Describes the humanoid local PathfindingService = game:GetService("PathfindingService") ---Makes a varibel of PathfindingService local Players = game.Players Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) while wait() do local path = PathfindingService:CreatePath() path:ComputerAsync(NPC.Torso.Position, char.Humanoid.Torso.Position) local waypoints = path:GetWaypoints() for i, waypoints in pairs(waypoints) do NPC:MoveTo(waypoints.Position) NPC.MoveToFinish:Wait(5) end end end) end) while wait() do NPC:MoveTo(char.Humanoid.Torso.Position) end
Basic error, look at the comment I left in the script:
local NPC = script.Parent --Describes the humanoid local PathfindingService = game:GetService("PathfindingService") ---Makes a varibel of PathfindingService local Players = game.Players Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) while wait() do local path = PathfindingService:CreatePath() path:ComputerAsync(NPC.Torso.Position, char.Humanoid.Torso.Position) local waypoints = path:GetWaypoints() for i , v waypoints in pairs(waypoints) do -- forgot to add v NPC:MoveTo(v.Position) -- Go to v, waypoints is a table NPC.MoveToFinish:Wait(5) end end end) end) while wait() do NPC:MoveTo(char.Humanoid.Torso.Position) end