Hello, i don’t really know what’s happening cause i’m a noob at pathfinding, i don’t know why it doesn’t work in game. I am also using a pathfinding Module Called SimplePath
Studio:
In-Game:
This worked before, now it just doesn’t work,
The Script:
local Root = script.Parent:WaitForChild("HumanoidRootPart")
local SimplePath = require(game.ReplicatedStorage.SimplePath)
local function findTarget()
local players = game.Players:GetPlayers()
local MaxDis = 80
local nearestTar
for index, player in pairs(players) do
if player.Character then
local Target = player.Character
local Distance = (script.Parent.HumanoidRootPart.Position - Target.HumanoidRootPart.Position).Magnitude
if Distance < MaxDis then
nearestTar = Target
MaxDis = Distance
end
end
end
return nearestTar
end
local function Attack(target)
local Distance = (script.Parent.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if Distance > 8 then
--script.Parent.Humanoid:MoveTo(target.HumanoidRootPart.Position)
local Path = SimplePath.new(script.Parent)
Path:Run(target.HumanoidRootPart.Position)
else
target.Humanoid.Health = 0
end
end
function wander()
local xRan = math.random(-80,80)
local zRan = math.random(-80,80)
local goal = Root.Position + Vector3.new(xRan,0,zRan)
local Path = game:GetService("PathfindingService"):CreatePath()
Path:ComputeAsync(Root.Position, goal)
if Path.Status == Enum.PathStatus.Success then
print("Success")
local WayPoints = Path:GetWaypoints()
for i,v in ipairs(WayPoints) do
if v.Action == Enum.PathWaypointAction.Jump then
Root.Parent.Humanoid.Jump = true
end
local Target = findTarget()
if Target then
Attack(Target)
break
else
local Path = SimplePath.new(script.Parent)
Path:Run(v.Position)
--Root.Parent.Humanoid:MoveTo(v.Position)
-- Root.Parent.Humanoid.MoveToFinished:Wait()
end
end
else
print("Failed")
end
end
while wait() do
local Target = findTarget()
if Target then
Attack(Target)
else
wander()
end
end
UPDATE:
I PUT FREE MODELS NPC AND THEY STILL DON"T MOVE IS THIS A BUG OR SOMETHING