Help with tweening a cooldown indicator and global cooldown

Yes I agree. I would even go as far as creating an object instead for these powerups if you’re interested. Here’s a basic hierarchy:

Disclaimer: in order to understand this make sure you are familiar and comfortable with OOP!!!

In Powerup Obj (module)

local powerup = {}
powerup.__index = powerup

function powerup.new()
   local newPowerup = setmetatable ({}, powerup)
   newPowerup.Debounce = false
   return newPowerup
end

return powerup

In a mock powerup (Like speed) (module)

local powerupObj = require (path.to.powerupModule)
local speedPower = {}
speedPower.__index = speedPower
setmetatable (speedPower, powerupObj)

function speedPower.new (basePowerup) -- ensure it's linked to the same base you link all other powerups
   local newSpeedPower = setmetatable(basePowerup, speedPower)
   local speedBoost = 10
   return newSpeedPower
end

function speedPower:Boost()
   if self.Debounce = false then -- add this check to all kinds of powerups
      self.Debounce = true
      -- do your speed boost stuff
      self.Debounce = false
   end
end

return speedPower

In main script (script)

   local powerupObj = require (path.to.powerupModule)
   local speedObj = require (path.to.speedModule)
   local newPower = powerupObj.new()
   local newSpeedpower = speedObj.new(newPower)
   -- now you can run speed power and like objects from here
   newSpeedPower:Boost()
   newSpeedPower:Boost() -- if debounce is on it won't run as it checks in the function

ADDED NOTE: A few perks about using OOP instead is that it’s easier debugging, more control over when powerups can be used when they’re tied to a central “Powerup hub” and it’s much, much, much easier to read when you come back to it sometime in the future as it’d be neater and more organized.

1 Like