Heya,
In my script, I am trying to make a block value change to true, but after x seconds it changes back UNLESS it gets set to true again which would reset the timer of x seconds, if that makes sense.
statusFolder["Stunned"].Value = true
delay(0.4,function()
--if tick() - secFromlastAttack >= 0.4 then ## was experimenting here
statusFolder["Stunned"].Value = false
--end
end)
That’s what I currently had.
Any help is appreciated!
A delay function is perfectly fine. It creates a new thread and continues running the rest of the script, and calls your function when the delay is up. If you don’t need the new thread, a wait() works just as fine.
Nono, basically I need some kind of detection system to see if the value was set to true again, hence why I tried to check if the previous attack distance was bigger than the current one, and if so then make the value false but it didn’t seem to work.
local debounce = false
statusFolder["Stunned"].Value = true
secFromlastAttack = tick() --this will reset to latest time every time player get stunned
-- I created this debounce to prevent creating a new thread again,
-- if you have a code below the task.spawn, probably you can put debounce inside task.spawn
if debounce then return end
debounce = true
task.spawn(function()
while statusFolder["Stunned"].Value then
if tick() - secFromlastAttack >= 0.4 then
statusFolder["Stunned"].Value = false
debounce = false
end
task.wait(.05)
end
end)
Edit : alright made some changes, thanks for feedback
YES! Thank you.
I changed some stuff around such as the debounce and wait times etc to make it fit in but the overall method works perfectly.
Thanks alot!
while task.wait() do
if statusFolder["Stunned"].Value do
task.wait(0.4)
stunnedOff()
end
end
function stunnedOff()
statusFolder["Stunned"].Value = false
end