So I recently learned how to use pathfinding service! anyway the problem Is where the NPC Isn't following the player
script:
local NPC = script.Parent local PathfindingService = game:GetService('PathfindingService') local Players = game:GetService('Players') local Player = Players:GetPlayerFromCharacter() local path = PathfindingService:CreatePath() path:ComputeAsync(NPC.Torso.Position, Player.Character.PrimaryPart.Position) if path.Status == Enum.PathStatus.Success then local Positions = path:GetWaypoints() for i,v in pairs(Positions) do local ball = Instance.new("Part", workspace) ball.Position = v.Position ball.Anchored = true ball.CanCollide = false ball.Size = Vector3.new(4,4,4) ball.Transparency = 0.5 NPC.Humanoid:MoveTo(v.Position) end end
I believe the issue is with line 4, in order to find the local player in a server script, use the "PlayerAdded" function.
Replace this with line 4:
local player game.Players.PlayerAdded:Connect(function(client) player = client end) repeat wait() until player ~= nil
I'm sorry about the delay!
P.S: The 'GetPlayerFromCharacter' function is to find the player if you know the character. e.g:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) print(player) -- Prints the player's name print(player.Parent -- prints "Players" end end)