Need help in understanding Sleitnick's car cooldown system

If anyone has ever watched Sleitnick’s How to rig a car tutorial series, you might notice his cooldown system. I’m currently having a hard time to understand it. How does it work? I know the intention of that system is to prevent your character from sitting back if you touch the basepart but it seems too complicated to me. Can anyone explain to me and help me understand it?
Here is the code from his video:
*local cooldown = 0

  • local function CoolDown(duration) *
  •       local cooldowntag = tick()*
    
  •       cooldown = cooldowntag*
    
  •       delay(duration, function()*
    
  •                 if cooldown = cooldowntag then*
    
  •                      cooldown = 0*
    
  •                 end*
    
  •       end)*
    
  • end*

Basically the most recent call to the function, “Cooldown” takes precedent. If you call cooldown(5) and then 3 seconds later, you call cooldown(3), the ‘clock’ restarts and begins to count down from three, disregarding your original countdown from 5.

1 Like