AdjustableTimerManager
The AdjustableTimerManager class manages multiple AdjustableTimer instances, providing functionality for replication, tag-based filtering, and client-server synchronization. It is designed to work in both server and client environments.
Example Usage
-- @SERVER
local manager = require(AdjustableTimerManager)
local timer = AdjustableTimer.new():Resume()
manager:ReplicateTimer(timer)
-- @CLIENT
local manager = require(AdjustableTimerManager)
local function watchTimer(timer)
-- do something with the timer
end
for _, timer in manager:GetAllReplicatedTimers() do
task.spawn(watchTimer, timer)
end
manager.TimerRegistered:Connect(function(timer, id)
watchTimer(timer)
end)
Types
TimerId
type
TimerId =
string
A unique identifier for the replication of an AdjustableTimer.
Tags
type
Tags =
{
[
any
]
:
any
}
Represents a dictionary of tags associated with a timer. Tags can be used to categorize or filter timers based on specific attributes.
local tags = { Category = "Game", Level = 5 }
TagMatchType
type
TagMatchType =
"exact"
|
"any"
|
"superset"
|
"subset"
Defines the type of matching to perform when comparing tags.
"exact"
: All key-value pairs in the tags must match exactly."any"
: At least one key-value pair in the tags must match."superset"
: The timer's tags must contain all key-value pairs of the given tags."subset"
: The timer's tags must be contained within the key-value pairs of the given tags.
Properties
TimerRegistered
Signal that fires when a timer is registered with the manager.
local connection = AdjustableTimerManager.TimerRegistered:Connect(function(timer, id)
print("Timer registered:", timer, id)
end)
TimerDisconnected
Signal that fires when a timer is disconnected from the manager.
local connection = AdjustableTimerManager.TimerDisconnected:Connect(function(timer, id)
print("Timer disconnected:", timer, id)
end)
Functions
ReplicateTimer
This item only works when running on the server. ServerReplicates a timer to all clients.
local id = AdjustableTimerManager:ReplicateTimer(timer, { Tag = "Example" })
Memory Leaks
Ensure to call AdjustableTimerManager:DisconnectTimer(timer)
when the timer is no longer needed to prevent memory leaks.
DisconnectTimer
This item only works when running on the server. ServerDisconnects a timer from the manager and stops replicating it to clients.
AdjustableTimerManager:DisconnectTimer(timer)
GetTimerFromId
Returns the timer associated with the given ID, or nil if it doesn't exist.
local timer = AdjustableTimerManager:GetTimerFromId(timerId)
GetTimerId
Returns the ID of the timer if it is registered, otherwise returns nil.
local id = AdjustableTimerManager:GetTimerId(timer)
GetTimerTags
Returns the tags associated with the given timer or timer ID. Tags are defined on the server when initially replicating the timer.
local tags = AdjustableTimerManager:GetTimerTags(timer)
GetTimersWithTags
AdjustableTimerManager:
GetTimersWithTags
(
) →
{
AdjustableTimer
}
--
An array of timers that satisfy the tag match.
Returns an array of timers that match the given tags.
local timers = AdjustableTimerManager:GetTimersWithTags({ Tag = "Example" })
PromiseFirstTimerWithTags
AdjustableTimerManager:
PromiseFirstTimerWithTags
(
) →
Promise
<
AdjustableTimer
>
--
A promise that resolves with the first matching timer.
Returns a promise that resolves with the first timer that matches the given tags. If no timer is found, it will wait for a timer to be registered that matches the tags.
AdjustableTimerManager:PromiseFirstTimerWithTags({ Tag = "Example" }):andThen(function(timer)
print(timer)
end)
PromiseTimerWithId
AdjustableTimerManager:
PromiseTimerWithId
(
) →
Promise
<
AdjustableTimer
>
--
A promise that resolves with the timer.
Returns a promise that resolves with the timer associated with the given ID.
Example Code
AdjustableTimerManager:PromiseTimerWithId(someTimerId):andThen(function(timer)
print(timer)
end)
GetAllReplicatedTimers
Returns an array of all replicated timers.
local timers = AdjustableTimerManager:GetAllReplicatedTimers()
SyncTimer
AdjustableTimerManager:
SyncTimer
(
player:
Player?
--
Optional player to sync the timer with. If not provided, syncs with all clients. (SERVER ONLY)
) →
Promise
<
TimerId,
SerializedAdjustableTimer
>
--
A promise that resolves with the timer ID and its serialized state.
If called on the client, it will request the server to sync the timer so that their states match.
If called on the server, it will sync the timer with all clients or a specific player.
This method should only need to be used if you perform some manual changes to the timer on the client side, such as pausing it. You will need to call this to resync the timer state with the server.
AdjustableTimerManager:SyncTimer(timerId):andThen(function(timerId, snapshot)
print("Timer synced:", timerId, snapshot)
end)