What do you want to achieve? Keep it simple and clear!
I am working on a combat system. Whenever the player gets hit, it cannot attack. I am doing this by using a BoolValue named “GotHit” and set the value to true when the player gets hit and then after a second, the value becomes false. I am using delay().
What is the issue? Include screenshots / videos if possible!
Unfortunately, it does not work as expected. When I punch the dummy twice, the value becomes false and then true immediately and then false again. Basically, the delay does not stop and/or get overrided by a new delay().
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking for solutions on the DevHub but I did not find any threads that could have a similar problem.
I would recommend using a debounce, this way it doesn’t trigger multiple times when being called, making the delay prominent
local isTouched = false -- Declare debounce variable
if not isTouched then -- Check that debounce variable is not true
isTouched = true -- Set variable to true
-- Your code here
isTouched = false -- Set variable to false
Yes I use something that I invented called an FID (function ID) - basically this is how it works:
local thisFID = os.clock()
globalFID = thisFID
if thisFID ~= globalFID then
-- prints("Not canceled!") once