Introduction
CounterService is a free, easy-to-use service for creating counters and timers in your Roblox game. Whether you need simple counters to track in-game statistics or timers for speedruns, this service will make it simple to implement these features.
Note: this is my first resource and new features will be added.
Features:
- Counters: Track numbers like player points, steps, items collected, and more.
- Timers: Easily add timers for various events, speed runs, or countdowns.
- Knit Supported: You can use this with knit too!
- Open-Source: Add custom functions based on your needs.
-
Signal Support: React to changes in counters and timers via events like
Updated
,Started
,Paused
, etc. -
Flexible Operations: Update counters with various operators such as
+
,-
,*
,/
.
How to Use
Counters
-
Create a Counter:
local CounterService = require(game.ReplicatedStorage.CounterService) local counter = CounterService:CreateCounter("MyCounter")
-
Get a Counter:
local counter = CounterService:GetCounter("MyCounter") print(counter.Count)
-
Update a Counter (with any operator):
-
Increment by 5:
local counter = CounterService:GetCounter("MyCounter") counter:Update("+", 5)
-
Multiply by 2:
counter:Update("*", 2)
-
-
Set a Counter to a Specific Value:
counter:Set(10)
-
Reset a Counter:
counter:Reset()
-
Remove a Counter:
CounterService:RemoveCounter("MyCounter")
-
Listen for Counter Updates:
- Example to track when a counter is updated:
local counter = CounterService:GetCounter("MyCounter") counter.Updated:Connect(function(updatedCounter) print(updatedCounter.Name .. " was updated. New count: " .. updatedCounter.Count) end)
- Example to track when a counter is updated:
Timers
-
Create a Timer:
local timer = CounterService:CreateTimer("SpeedRunTimer")
-
Update a Timer:
timer:Update() print(timer.Minutes, timer.Seconds, timer.Milliseconds)
-
Set Timer Value:
timer:Set(2, 30, 500) -- Set to 2 minutes, 30 seconds, and 500 milliseconds
-
Start a Timer:
timer:Start()
-
Pause a Timer:
timer:Pause()
-
Stop a Timer:
timer:Stop()
-
Listen for Timer Events:
- Example to detect when a timer is paused:
timer.PausedSignal:Connect(function(pausedTimer) print(pausedTimer.Name .. " was paused.") end)
- Example to detect when a timer is paused:
Tutorial: Setting Up and Using CounterService
Step 1: Importing CounterService
- Save the CounterService script in your
ReplicatedStorage
folder.
Step 2: Setting Up a Counter
- Create a counter in your server script:
local CounterService = require(game.ReplicatedStorage.CounterService) CounterService:CreateCounter("ScoreCounter")
Step 3: Working with Counters
- Increment your counter by 10:
local counter = CounterService:GetCounter("ScoreCounter") counter:Update("+", 10) print("Player score:", counter.Count)
Step 4: Timers
- Create and start a timer for a speedrun:
local timer = CounterService:CreateTimer("SpeedRunTimer") timer:Start() -- Simulate updating the timer every second while wait(1) do timer:Update() print(timer.Minutes, timer.Seconds, timer.Milliseconds) end
Example Usage Example:
You can extend CounterService to listen for updates, changes, and pauses in both counters and timers by connecting to the appropriate signals. This allows you to trigger specific game events when a counter or timer reaches a certain threshold.
For example, to detect when a counter reaches a score of 100:
local counter = CounterService:GetCounter("ScoreCounter")
counter.Updated:Connect(function(updatedCounter)
if updatedCounter.Count >= 100 then
print("Player has reached 100 points!")
-- Trigger any specific game logic here
end
end)