Per-Player Interaction Cooldown Module thumbnail
0 views0 copies0 likes

Per-Player Interaction Cooldown Module

Universal script

Copy it, then test it in your own Studio place.

Utilities Verified

Script code

15 lines · 0.4 KB
Download
local Cooldowns = {}local deadlines = setmetatable({}, {__mode = "k"})function Cooldowns.Try(caller, action, seconds)	local state = deadlines[caller] or {}	deadlines[caller] = state	local now = os.clock()	local remaining = (state[action] or now) - now	if remaining > 0 then return false, remaining end	state[action] = now + math.max(seconds, 0)	return true, 0endfunction Cooldowns.Clear(caller)	deadlines[caller] = nilend-- …open Get script for the full source

About this script

Create a ModuleScript named Cooldowns and call its Try method from interaction handlers. Give each action a key and a minimum interval. The module remembers deadlines separately for each caller and action, and returns remaining seconds to display feedback. Use a Player instance as the caller and call Clear when resetting that player's interactions. Start with a low-stakes use such as a shop greeting.

Comments

Share what works, ask questions, or report an issue.

0

Log in to leave a comment.

No comments yet

Be the first to share your thoughts!

Raw Luau source

local Cooldowns = {}
local deadlines = setmetatable({}, {__mode = "k"})
function Cooldowns.Try(caller, action, seconds)
	local state = deadlines[caller] or {}
	deadlines[caller] = state
	local now = os.clock()
	local remaining = (state[action] or now) - now
	if remaining > 0 then return false, remaining end
	state[action] = now + math.max(seconds, 0)
	return true, 0
end
function Cooldowns.Clear(caller)
	deadlines[caller] = nil
end
return Cooldowns