Skip to main content

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

AdjustableTimerManager.TimerRegistered: Signal<AdjustableTimer,TimerId>

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

AdjustableTimerManager.TimerDisconnected: Signal<AdjustableTimer,TimerId>

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. Server
AdjustableTimerManager:ReplicateTimer(
timerAdjustableTimer,--

The timer to replicate.

tagsTags?--

Optional tags to associate with the timer.

) → TimerId--

The ID of the replicated timer.

Replicates 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. Server
AdjustableTimerManager:DisconnectTimer(
timerAdjustableTimer--

The timer to disconnect.

) → ()

Disconnects a timer from the manager and stops replicating it to clients.

AdjustableTimerManager:DisconnectTimer(timer)

GetTimerFromId

AdjustableTimerManager:GetTimerFromId(idTimerId) → AdjustableTimer?

Returns the timer associated with the given ID, or nil if it doesn't exist.

local timer = AdjustableTimerManager:GetTimerFromId(timerId)

GetTimerId

AdjustableTimerManager:GetTimerId(timerAdjustableTimer) → TimerId?

Returns the ID of the timer if it is registered, otherwise returns nil.

local id = AdjustableTimerManager:GetTimerId(timer)

GetTimerTags

AdjustableTimerManager:GetTimerTags(
timerAdjustableTimer | TimerId--

The timer or timer ID to get tags for.

) → Tags?--

The tags associated with the timer.

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(
tagsToMatchTags,--

The tags to match against.

matchTypeTagMatchType?--

The type of tag matching to perform. Defaults to "exact".

) → {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(
tagsToMatchTags,--

The tags to match against.

matchTypeTagMatchType?--

The type of tag matching to perform. Defaults to "exact".

) → 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(
idTimerId--

The ID of the timer to find.

) → 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

AdjustableTimerManager:GetAllReplicatedTimers() → {AdjustableTimer}

Returns an array of all replicated timers.

local timers = AdjustableTimerManager:GetAllReplicatedTimers()

SyncTimer

AdjustableTimerManager:SyncTimer(
timerTimerId | AdjustableTimer,--

The timer or ID of the timer to sync.

playerPlayer?--

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)
Show raw api
{
    "functions": [
        {
            "name": "Start",
            "desc": "Initializes the manager and sets up replication for timers.\n```lua\nAdjustableTimerManager:Start()\n```",
            "params": [],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 265,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "ReplicateTimer",
            "desc": "Replicates a timer to all clients.\n```lua\nlocal id = AdjustableTimerManager:ReplicateTimer(timer, { Tag = \"Example\" })\n```\n:::caution Memory Leaks\nEnsure to call `AdjustableTimerManager:DisconnectTimer(timer)` when the timer is no longer needed to prevent memory leaks.\n:::",
            "params": [
                {
                    "name": "timer",
                    "desc": "The timer to replicate.",
                    "lua_type": "AdjustableTimer"
                },
                {
                    "name": "tags",
                    "desc": "Optional tags to associate with the timer.",
                    "lua_type": "Tags?"
                }
            ],
            "returns": [
                {
                    "desc": "The ID of the replicated timer.",
                    "lua_type": "TimerId"
                }
            ],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 318,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "DisconnectTimer",
            "desc": "Disconnects a timer from the manager and stops replicating it to clients.\n```lua\nAdjustableTimerManager:DisconnectTimer(timer)\n```",
            "params": [
                {
                    "name": "timer",
                    "desc": "The timer to disconnect.",
                    "lua_type": "AdjustableTimer"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 348,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "GetTimerFromId",
            "desc": "Returns the timer associated with the given ID, or nil if it doesn't exist.\n```lua\nlocal timer = AdjustableTimerManager:GetTimerFromId(timerId)\n```",
            "params": [
                {
                    "name": "id",
                    "desc": "",
                    "lua_type": "TimerId"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "AdjustableTimer?\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 359,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "GetTimerId",
            "desc": "Returns the ID of the timer if it is registered, otherwise returns nil.\n```lua\nlocal id = AdjustableTimerManager:GetTimerId(timer)\n```",
            "params": [
                {
                    "name": "timer",
                    "desc": "",
                    "lua_type": "AdjustableTimer"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "TimerId?\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 369,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "GetTimerTags",
            "desc": "Returns the tags associated with the given timer or timer ID.\nTags are defined on the server when initially replicating the timer.\n```lua\nlocal tags = AdjustableTimerManager:GetTimerTags(timer)\n```",
            "params": [
                {
                    "name": "timer",
                    "desc": "The timer or timer ID to get tags for.",
                    "lua_type": "AdjustableTimer | TimerId"
                }
            ],
            "returns": [
                {
                    "desc": "The tags associated with the timer.",
                    "lua_type": "Tags?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 382,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "GetTimersWithTags",
            "desc": "Returns an array of timers that match the given tags.\n```lua\nlocal timers = AdjustableTimerManager:GetTimersWithTags({ Tag = \"Example\" })\n```",
            "params": [
                {
                    "name": "tagsToMatch",
                    "desc": "The tags to match against.",
                    "lua_type": "Tags"
                },
                {
                    "name": "matchType",
                    "desc": "The type of tag matching to perform. Defaults to \"exact\".",
                    "lua_type": "TagMatchType?"
                }
            ],
            "returns": [
                {
                    "desc": "An array of timers that satisfy the tag match.",
                    "lua_type": "{ AdjustableTimer }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 400,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "PromiseFirstTimerWithTags",
            "desc": "Returns a promise that resolves with the first timer that matches the given tags.\nIf no timer is found, it will wait for a timer to be registered that matches the tags.\n```lua\nAdjustableTimerManager:PromiseFirstTimerWithTags({ Tag = \"Example\" }):andThen(function(timer)\n\tprint(timer)\nend)\n```",
            "params": [
                {
                    "name": "tagsToMatch",
                    "desc": "The tags to match against.",
                    "lua_type": "Tags"
                },
                {
                    "name": "matchType",
                    "desc": "The type of tag matching to perform. Defaults to \"exact\".",
                    "lua_type": "TagMatchType?"
                }
            ],
            "returns": [
                {
                    "desc": "A promise that resolves with the first matching timer.",
                    "lua_type": "Promise<AdjustableTimer>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 425,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "PromiseTimerWithId",
            "desc": "Returns a promise that resolves with the timer associated with the given ID.\n\n**Example Code**\n```lua\nAdjustableTimerManager:PromiseTimerWithId(someTimerId):andThen(function(timer)\n\tprint(timer)\nend)\n```",
            "params": [
                {
                    "name": "id",
                    "desc": "The ID of the timer to find.",
                    "lua_type": "TimerId"
                }
            ],
            "returns": [
                {
                    "desc": "A promise that resolves with the timer.",
                    "lua_type": "Promise<AdjustableTimer>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 461,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "GetAllReplicatedTimers",
            "desc": "Returns an array of all replicated timers.\n```lua\nlocal timers = AdjustableTimerManager:GetAllReplicatedTimers()\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ AdjustableTimer }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 490,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "SyncTimer",
            "desc": "If called on the client, it will request the server to sync the timer so that their states match.\n\nIf called on the server, it will sync the timer with all clients or a specific player.\n\nThis method should only need to be used if you perform some manual changes to the timer on the client side, such\nas pausing it. You will need to call this to resync the timer state with the server.\n\n```lua\nAdjustableTimerManager:SyncTimer(timerId):andThen(function(timerId, snapshot)\n\tprint(\"Timer synced:\", timerId, snapshot)\nend)\n```",
            "params": [
                {
                    "name": "timer",
                    "desc": "The timer or ID of the timer to sync.",
                    "lua_type": "TimerId | AdjustableTimer"
                },
                {
                    "name": "player",
                    "desc": "Optional player to sync the timer with. If not provided, syncs with all clients. (SERVER ONLY)",
                    "lua_type": "Player?"
                }
            ],
            "returns": [
                {
                    "desc": "A promise that resolves with the timer ID and its serialized state.",
                    "lua_type": "Promise<TimerId, SerializedAdjustableTimer>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 518,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "TimerRegistered",
            "desc": "Signal that fires when a timer is registered with the manager.\n```lua\nlocal connection = AdjustableTimerManager.TimerRegistered:Connect(function(timer, id)\n\tprint(\"Timer registered:\", timer, id)\nend)\n```",
            "lua_type": "Signal<AdjustableTimer, TimerId>",
            "source": {
                "line": 243,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "TimerDisconnected",
            "desc": "Signal that fires when a timer is disconnected from the manager.\n```lua\nlocal connection = AdjustableTimerManager.TimerDisconnected:Connect(function(timer, id)\n\tprint(\"Timer disconnected:\", timer, id)\nend)\n```",
            "lua_type": "Signal<AdjustableTimer, TimerId>",
            "source": {
                "line": 255,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        }
    ],
    "types": [
        {
            "name": "TimerId",
            "desc": "A unique identifier for the replication of an AdjustableTimer.",
            "lua_type": "string",
            "source": {
                "line": 24,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "Tags",
            "desc": "Represents a dictionary of tags associated with a timer. Tags can be used to categorize or filter timers based on specific attributes.\n```lua\nlocal tags = { Category = \"Game\", Level = 5 }\n```",
            "lua_type": "{ [any]: any }",
            "source": {
                "line": 34,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        },
        {
            "name": "TagMatchType",
            "desc": "Defines the type of matching to perform when comparing tags.\n\n- `\"exact\"`: All key-value pairs in the tags must match exactly.\n- `\"any\"`: At least one key-value pair in the tags must match.\n- `\"superset\"`: The timer's tags must contain all key-value pairs of the given tags.\n- `\"subset\"`: The timer's tags must be contained within the key-value pairs of the given tags.",
            "lua_type": "\"exact\" | \"any\" | \"superset\" | \"subset\"",
            "source": {
                "line": 46,
                "path": "lib/adjustabletimermanager/src/init.luau"
            }
        }
    ],
    "name": "AdjustableTimerManager",
    "desc": "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.\n\n### Example Usage\n```lua\n-- @SERVER\nlocal manager = require(AdjustableTimerManager)\nlocal timer = AdjustableTimer.new():Resume()\nmanager:ReplicateTimer(timer)\n```\n```lua\n-- @CLIENT\nlocal manager = require(AdjustableTimerManager)\nlocal function watchTimer(timer)\n\t-- do something with the timer\nend\n\nfor _, timer in manager:GetAllReplicatedTimers() do\n\ttask.spawn(watchTimer, timer)\nend\nmanager.TimerRegistered:Connect(function(timer, id)\n\twatchTimer(timer)\nend)\n```",
    "source": {
        "line": 230,
        "path": "lib/adjustabletimermanager/src/init.luau"
    }
}