Ok so I made this pathfinding script but it says that LocalPlayer is a nil value. What other variable should i use. Here is my script.
while wait() do
local path = game:GetService("PathfindingService")
path:ComputeRawPathAsync(script.Parent.Torso.Position,
game.Players.LocalPlayer.Character.Torso.Position)
if path.Status == Enum.PathStatus.Success then
local points = path:GeetWaypoints()
if#points < 3 then
script.Parent.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
else
script.Parent.Humanoid:MoveTo(points[3])
end
else
script.Parent.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
end
end
function OnTouched()
script.Parent.Torso.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
hit.Parent.Humanoid.Health = 0
end
end)
end

3 comments
scripts not in script holder :/
run it in a local script so you can use local player. pathfinding should be done on the client if it's pathfinding for the player. if it's an NPC, you already know what character you are going to use so you can replace the character variable with the npc
the script is inside the npc.