Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//Hopefully you find this module in some way usefull
- --//More info here https://devforum.roblox.com/t/1399553
- --//Created by AllAllLol1\\
- local Cooldown = {}
- local CooldownList = {}
- local function UpdateTime(startTime, tableName, valueName) --This function is completely additional and can be removed or edited if you know what your doing
- if CooldownList[tableName] then
- if CooldownList[tableName][valueName] then
- local OriginalTime = CooldownList[tableName][valueName] --Original cooldown duration
- while wait() do
- local currentTime = os.time()
- local timePassed = currentTime - startTime
- local timeLeft = OriginalTime - timePassed
- if OriginalTime >= timePassed then --I dont want the local [timeLeft] variable to change the actual variable inside the table to a negative integer
- CooldownList[tableName][valueName] = timeLeft
- else
- CooldownList[tableName][valueName] = 0 --Else it will just be 0
- break --Break the while loop
- end
- end
- end
- end
- end
- local function WaitCooldown(tableName, valueName, Time) --This function will wait for the cooldown to finish and then delete the value from the player table or the player table itself if its empty
- local startTime = os.time()
- local newThread = coroutine.create(UpdateTime)
- coroutine.resume(newThread, startTime, tableName, valueName)
- wait(Time) --This line waits in seconds (local [UpdateTime] function does not change local [Time] variable)
- for i, ii in next, CooldownList[tableName] do
- if i == valueName then
- CooldownList[tableName][ii] = nil
- table.remove(CooldownList[tableName],i)
- end
- end
- if #CooldownList[tableName] == 0 then
- CooldownList[tableName] = nil
- end
- end
- function Cooldown.Add(tableName, valueName, cooldown) -- This function will insert a table for each diffirent player with diffirent cooldown values for diffirent valueName
- if tonumber(cooldown) ~= nil then --This line is to make sure that passed variable [cooldown] isn't nil and has interger(s)
- if CooldownList[tableName] then
- table.insert(CooldownList[tableName], valueName)
- CooldownList[tableName][valueName] = cooldown
- local newThread = coroutine.create(WaitCooldown)
- coroutine.resume(newThread, tableName, valueName, cooldown)
- return true
- else
- CooldownList[tableName] = {[valueName] = cooldown}
- local newThread = coroutine.create(WaitCooldown)
- coroutine.resume(newThread, tableName, valueName, cooldown)
- return true
- end
- end
- return false
- end
- function Cooldown.Check(tableName, valueName) --This function will check [CooldownList] table in order to know if the value already exists
- if CooldownList[tableName] then
- if CooldownList[tableName][valueName] then
- local timeLeft = CooldownList[tableName][valueName] --If the local [UpdateTime] function is used it will return the time that is left else it will return the starting local [cooldown] variable in Module [Add] function
- return false, timeLeft
- else
- return true
- end
- else
- return true
- end
- end
- return Cooldown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement