Not sure what’s wrong here. path variable just doesn’t work? Cant index path for some reason.
local PathfindingService = game:GetService("PathfindingService")
local Pets = require(game.ServerScriptService.Pets)
local PetStats = Pets.new(25,0.5,10)
local Pet = script.Parent
local Humanoid = Pet:WaitForChild("Humanoid")
local HumanoidRootPart = Pet.HumanoidRootPart
local AgentParams = {
AgentHeight = 5,
AgentCollisionGroupName = "Pets",
AgentCanJump = true
}
local Path = PathfindingService:CreatePath()
local Goal
local GoToFood = coroutine.create(function()
while true do
local FoodsAvailable = workspace.FoodsAvailable:GetChildren()
Goal = FoodsAvailable[math.random(1,#FoodsAvailable)]
coroutine.yield()
end
end)
coroutine.resume(GoToFood)
local function WalkTo()
print(HumanoidRootPart.Position, Goal.Position)
local path = Path:ComputeAsync(HumanoidRootPart.Position, Goal.Position)
if path.Status == Enum.PathStatus.Success then
local Waypoints = path:GetWaypoints()
for i,Waypoint in pairs(Waypoints) do
if Goal == nil then
path:Destroy()
end
if Waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
if Goal then
Humanoid:MoveTo(Goal)
Humanoid.MoveToFinished:Wait()
coroutine.resume(GoToFood)
break
else
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
end
end
end
while true do
WalkTo()
wait()
end