So I made a script that follows the player (But not only that but also has pathfinding! (Meaning It can go around walls when the player Is behind one and something similar about It)) but the problem Is where It can't spot the player when Its spawned on top of a tower (Ex: A office building, The classic roblox tower, A literal tree, etc)
script:
local NPC = script.Parent
local PathFinding = game:GetService("PathfindingService")
local player
game.Players.PlayerAdded:Connect(function(client)
player = client
end)
repeat wait() until player ~= nil
local path
while wait() do
path = PathFinding: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 Position = Instance.new("Part")
Position.Parent = game.Workspace
Position.Position = v.Position
Position.Size = Vector3.new(3,3,3)
Position.Anchored = true
Position.CanCollide = false
Position.Transparency = 1
NPC.Humanoid:MoveTo(Position.Position)
NPC.Humanoid.MoveToFinished:Wait(2)
Position:Destroy()
end
end
end
