I'm making an military game, mostly including NPCs. Every NPC has a binded bool value called "shooting", that sets on "true" when NPC is shooting, and turns "false" when NPC stops shooting.
My goal is to detect if NPC isn't shooting for, let's say, 5 seconds. Script can detect that by reading "shooting" value, but I don't know how would I detect that it doesn't change. That's what I achieved so far, but it doesn't really work.
local debouce = false local value, changed = nil, false script.Value.Changed:Connect(function(newValue) changed = true value = newValue wait(5) if newValue == value and changed == false then print("Not changing!") end changed = false end)
Thanks in advance!
Krzysiek
Nevermind, I've figured it out by myself :)
For those who are wondering how I've achieved this:
local value, flag = nil, 0 script.Value.Changed:Connect(function(newValue) flag = flag + 1 if newValue ~= false then return end local localFlag = flag value = newValue wait(5) if newValue == value and flag == localFlag then print("Not changing!") end end)