How can i make my ai Teleport Back to a block if its stuck for 3 seconds

Hello, I’m trying to make it where if my AI’S Speed is 1 or below for more than 3 Seconds it will teleport to a block, if its stuck for 2 seconds and moves again it doesn’t teleport, I Currently Only have the script to do a function if its speed is 1 but i dont have the part of the script to make it wait 5 seconds to teleport back

Script


Humanoid.Running:Connect(function(Speed)
	    if Speed < 1 then  
		 
	end
end)
1 Like

This post will be helpful.

1 Like

This is very primitive and I see a solution has already been provided but I wanted to offer one for the script which was posted.

local stopped = 0
local debounce = false

Humanoid.Running:Connect(function(Speed)
	if debounce then
		return
	end
	debounce = true
	if Speed < 1 then
		stopped += 1
		if stopped >= 5 then
			--perform teleport here
			stopped = 0 --reset stat
		end
	end
	task.wait(1)
	debounce = false
end)
2 Likes

Yeah it’s much smarter to wait until it has been stopped 5 times instead of waiting 1 second every time and checking if the position is the same. I might try this.