Get module for free here: Module - Roblox
- How is this module helpful?
The module is fairly simple to understand but also quite useful. This module allows developers to create cooldowns that will be stored in a table inside of a module. The module has a function that checks if the cooldown is still in progress and returns the rest of the time duration (in seconds) that is left to wait until the cooldown is finished.
- How to use it?
A simple example would be a sword script line that fires a remote event. OnServerRemote event function will have those lines of code:
local CooldownMod = require(game:GetService("ReplicatedStorage"):WaitForChild("CooldownModule")) --Get module for free https://www.roblox.com/library/7222244363
SwordAttack.OnServerEvent:Connect(function(player) then
local checkResult, timeLeft = CooldownMod.Check(player.Name, "Sword")
if checkResult then
CooldownMod.Add("AllAllLol1", "Sword", 1.2)
--Script
else
SwordAttack:FireClient(player, checkResult, timeLeft) --return checkResult and time that is left until the finish of cooldown
end
end
You don’t exactly have to format your code in that way.
However, let me explain what I’ve written the first line inserts the module. Then I check if the same existing cooldown data already exists in the cooldown module by using the “Check” function in the cooldown module; if it does it will return false if not it returns true. After if “Check” function returns true it will use the “Add” function to add cooldown data.
- Module Functions
The “Add” function requires 3 variables the first variable is the table name (this is useful if you have multiple objects that use the same cooldown(s)), the second variable would be the name of the cooldown (that way you can have multiple different cooldowns running for different events for the same object). The last variable is the wait duration.
The “NewUpdateThread” function you guessed it - updates the duration value for all values inside the object table as time progresses. Once the time left of the duration is 0 the cooldown value is removed.
The “Check” function requires 2 variables, the table name, and the cooldown name.
Check function will return true if the table is not found, and it will return true if the cooldown name isn’t found. if it’s found it will return false with the value duration of the cooldown that is updated by the local “UpdateTime” in the module.
Hopefully, you’ll find it very useful since this is an especially great module for newer developers.