Hello. I’m having a problem with NPC getting stuck so I wanted to make a script that every 15 seconds it checks if NPC is stuck or not, if NPC is stuck then NPC CFrame will be equal to his spawn, else it checks again. But it’s not working, even when NPC is chasing me it teleports him to his spawn.
Script:
local humanoid = script.Parent:WaitForChild("Humanoid")
while wait(15) do
if humanoid.MoveDirection == Vector3.zero then
script.Parent.HumanoidRootPart.CFrame = game.Workspace.SpawnPatrick.CFrame
else end
end
Actually, instead of checking if the MoveDirection is 0, you need to check if it’s not 0, as that would mean the NPC is trying to move.
My suggestion is, every X seconds (maybe something like 10 seconds) check if the NPC is trying to move and if the position is the same as the position from 10 seconds ago. If it’s the same then the NPC is most likely stuck somewhere.