#NPC AI issue related to MoveToFinished
1 messages · Page 1 of 1 (latest)
So basically the ai works fine for a bit however, after a while it breaks for some reason I don't know why, Like it'll move to a few waypoints then stop for no apparent reason, the state changes work fine and there is no random state change between walk cycles
Thank you for your help
self.MoveToConnection = Humanoid.MoveToFinished:Connect(function(reached)
if not reached then self.WalkFinished:Fire(); return end
index += 1
if index <= #Waypoints then
Humanoid:MoveTo(Waypoints[index].Position)
else
self.WalkFinished:Fire()
end
end)``` pathfinding cancels part way through if the waypoint is not reached, and you are making duplicate connections to MoveToFinished event.
those duplicate connections are going to cause a lot of problems for any future pathfinding, they not able to get past the first waypoint
I'm pretty sure the issue of duplicate connections I already solved by disconnecting the events
though I'll look into the cancelling part way through due to reached
but like the thing is
when if Walkfinished fires, I recompute a new path
... without destroying the old MoveToConnection.
just because you put it in a variable doesnt mean the old one gets disconnected when you overwrite it 
...not when you fire WalkFinished.
Walkfinished just call walk path, and inside walk path I cancel the walk
if a connection exist
like disconnect
function GrandmaObject.WalkPath(self:Grandma, Destination:Vector3)
if not Destination then return end
self:CancelWalk()``` there it is
missed that
yup
np
its the fact that it likes move to the second waypoint, then just stops that confuses me
and before hand it works fine
its just after like 4-5 cycles
its stops working
increase the agent radius
ok I will try, but how would that help?
likely getting jammed on a wall or something
its not that, like its basically just constantly traversing a house and what not, and even if it gets blocked it should recompute a path, and besides after the 4-5 cycles the problems keeps on repeating itself
but anyways trying right now
I'll tell you if it works
the ai works similar to granny
i remember having a similar issue with my npc
cant remember what i did to fix it, but one of the symptoms was the waypoint visualizer kept rising up out of the ground and into the air, eventually becoming unreachable
i also think you may need more handling around lua if Path.Status ~= Enum.PathStatus.Success then return end here add a warn
particularly while devving
Nope it creates the waypoints and they are all on the ground however it walks for a few seconds then just stops for some reason
oh ye sure
the script is still a work in progress, there still some stuff I want to refine but for now I just want to get this issue over with
ok so I think I noticed something
The path computes and what not
and the npc will continue walking that path
however will stop near an object whether its a wall or what not
I still don't get why it works before though
then stops randomly
ya increase agent radius
so it doesnt get too close to wall
also review navmesh
use the roblox navmesh visualizer thingy, google the setting name
i suspect it may be trying to pathfind through a wall
or over it, rather
pathfinder tricky thing, lots of possible issues
I use the navmesh visualiser, the path is computed and looks completely fine
it could still be your state machine
could try moving the npc while the game is running to see what happens, on the server ofc
Oh ye sure imma try that
debugging bruuh
and you didn't try that already?
nope 😭
so its probably just getting jammed on something
keep trialing stuff
specially now you have clear, easily reproducible symptom
actually thinking about it, it could also be network ownership
for i,v:BasePart in self.Character:GetDescendants() do
if v:IsA("BasePart") then v:SetNetworkOwner(nil) end
end``` looks fine
yup I had that issue a while ago but I fixed it
ok now sometimes it walks to third and 4th waypoint, however it like stutters for some reason
Oh one more thing @silent folio , you think this is S2 or nah?
you are struggling to debug it, what do you think
okay vro
can't just look right, has to be right too 
I think after I fix it though should be worth S2, got alot of things built into it and what not but I'll still see, I don't want to make an application too soon
thanks for your help, if you have any more ideas please be sure to share them
nah I lied
ye I think its a network owner ship issue
I used the Network Owner thing in the settings
and for some reason the character parts become are green
which in the docs means that they are owned by my character