Bet on live player counts in a Roblox game

A rise-or-fall game on the Roblox Template - players bet coins on whether a real game's players go up, settled from live market readings through PlatformService.

Roblox games

This recipe turns the market board into a game: a player bets coins that a real Roblox game's players will rise or fall over the next 15 minutes, and the server settles the bet from the platform's next reading of that game. Every number comes from PlatformService.games, read once a minute for the whole game, so it costs the key one request a minute per 40 games, however many servers run.

Before you start

  • A game on the Roblox Template with platform switched on and the BlockoutApiKey secret set. See Setting up the BlockoutApiKey secret.

  • The market board from Building a market game in place: SharedState.marketPlayers refreshed every 60 seconds by PlayersBoardService.

  • The universe ids of the games to bet on, each tracked by the platform. Open /games/<universe id> in the panel to check one, or to start tracking it.

  • A currency to stake. The Template's CurrencyService holds coins.

How a bet is settled

A game's ccu is the players at its last reading, lastSnapshotAt, and the collector reads a game every 5 minutes to once a week by its tier. A bet is only fair when a new reading arrives inside the round, so this recipe takes bets only on hot games (read every 5 minutes) and active games (every 15), and refunds a bet whose game was not read again.

One bet. A player bets on a hot or active game; the server takes the stake and notes the game's players and reading time. Fifteen minutes later it looks at the board again. If the game was not read again, or its players are unchanged, the stake is refunded. Otherwise a right call pays twice the stake and a wrong one pays nothing.

Steps

  1. Keep each game's tier on the board

    In SharedState.luau, add tier: string? to the marketPlayers atom's row type. In PlayersBoardService's refresh loop, add tier = item.tier, to the row it writes.

  2. Add the betting service

    Create src/main/server/Services/MarketBetService.luau with the code below. It takes the stake, notes the game's ccu and lastSnapshotAt, and settles after 15 minutes.

  3. List its currency reasons for analytics

    In Config/Overrides/Analytics.luau, add the three reasons to economy: economy = { market_bet = "Gameplay", market_bet_refund = "Gameplay", market_bet_won = "Gameplay" }. The Template's analytics coverage spec fails lune run check on a currency reason it cannot find there.

  4. Call it from a remote

    Wire a remote whose handler checks the shape of what the client sent and calls MarketBetService.place(player, gameId, up, stake). Every check that matters (the stake, the game, one bet at a time) is in the service, on the server. See Shape checks and meaning checks.

  5. Show the board and the bet

    The board's client controller already draws every game's players and its 1-hour change. Mark the games whose tier is hot or active as open for bets.

  6. Test it in Studio

    With the secret in Studio's Local Secrets, run the server, place a bet on a hot game, and lower ROUND_SECONDS while testing. Run the staff platform command if nothing arrives.

src/main/server/Services/MarketBetService.luau
--!strictlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local Result = require(ReplicatedStorage.Shared.Util.Result)local SharedState = require(ReplicatedStorage.Shared.SharedState)local CurrencyService = require(script.Parent.Parent.Parent.Services.CurrencyService)local ROUND_SECONDS = 15 * 60local MAX_STAKE = 1000local PAYOUT = 2 -- a right call returns twice the stakelocal MarketBetService = {}-- Skipped by the Loader while Config/Features.platform is off.MarketBetService.feature = "platform"local running: { [Player]: boolean } = {}-- Only games read at least every 15 minutes, with a known count and a fresh answer.local function bettable(row): boolean	return row ~= nil		and row.ccu ~= nil		and not row.stale		and (row.tier == "hot" or row.tier == "active")endlocal function settle(player: Player, gameId: string, up: boolean, stake: number, openCcu: number, openAt: string?)	running[player] = nil	if player.Parent == nil then		return -- shortcut: a player who left loses the stake; keep open bets in saved data for a real game	end	local row = SharedState.marketPlayers()[gameId]	if not bettable(row) or row.lastSnapshotAt == openAt or row.ccu == openCcu then		CurrencyService.add(player, "coins", stake, "market_bet_refund")		return	end	if (row.ccu > openCcu) == up then		CurrencyService.add(player, "coins", stake * PAYOUT, "market_bet_won")	endend-- Called from the remote's handler. `gameId` is a universe id as text, as the board keys it.function MarketBetService.place(player: Player, gameId: string, up: boolean, stake: number): Result.Result<number>	if running[player] then		return Result.err("busy", "You already have a bet running.")	end	if stake ~= math.floor(stake) or stake < 1 or stake > MAX_STAKE then		return Result.err("bad_stake", `Bet between 1 and {MAX_STAKE} coins.`)	end	local row = SharedState.marketPlayers()[gameId]	if not bettable(row) then		return Result.err("closed", "That game cannot be bet on right now.")	end	local paid = CurrencyService.spend(player, "coins", stake, "market_bet")	if not paid.ok then		return paid	end	running[player] = true	local openCcu, openAt = row.ccu, row.lastSnapshotAt	task.delay(ROUND_SECONDS, settle, player, gameId, up, stake, openCcu, openAt)	return Result.ok(stake)endreturn MarketBetService

What the game costs the key

ReadRequests a minute, whole game
The board, per group of 40 ids1
A bet placed or settled0: it reads the board
history(id, "24h") for one chart1 every 5 minutes per game

The key allows 120 a minute for every server together. Keep each ids group to about 40 and in a fixed order, so the answer fits the shared cache. The rules: Errors, limits and polling.

Ideas on the same reads

  • A chart beside each bet: PlatformService.history(id, "24h") gives a game's players in 5-minute buckets. See GET /developer/v1/games/:id/history.

  • Odds from momentum: growth1h (0.5 is +50% in the last hour) is on every row; pay more on a bet against it.

  • New games to bet on: PlatformService.games({ sort = "breakout", limit = 20 }) lists the games breaking out now. Keep the list fixed for a round, so its ids stay one cache entry.

What you get

A board of real Roblox games refreshed every minute in every server, bets that settle on the platform's next reading of each game, refunds when no reading arrives, and a key that spends one request a minute per 40 games.

Updated