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
platformswitched on and theBlockoutApiKeysecret set. See Setting up the BlockoutApiKey secret.The market board from Building a market game in place:
SharedState.marketPlayersrefreshed every 60 seconds byPlayersBoardService.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
CurrencyServiceholdscoins.
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.
Steps
Keep each game's tier on the board
In
SharedState.luau, addtier: string?to themarketPlayersatom's row type. InPlayersBoardService's refresh loop, addtier = item.tier,to the row it writes.Add the betting service
Create
src/main/server/Services/MarketBetService.luauwith the code below. It takes the stake, notes the game'sccuandlastSnapshotAt, and settles after 15 minutes.List its currency reasons for analytics
In
Config/Overrides/Analytics.luau, add the three reasons toeconomy:economy = { market_bet = "Gameplay", market_bet_refund = "Gameplay", market_bet_won = "Gameplay" }. The Template's analytics coverage spec failslune run checkon a currency reason it cannot find there.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.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
tierishotoractiveas open for bets.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_SECONDSwhile testing. Run the staffplatformcommand if nothing arrives.
--!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 MarketBetServiceWhat the game costs the key
| Read | Requests a minute, whole game |
|---|---|
| The board, per group of 40 ids | 1 |
| A bet placed or settled | 0: it reads the board |
history(id, "24h") for one chart | 1 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.
The board this recipe builds on.
The Template's platform service
Every call, the shared cache, the reasons a call fails.
Which route answers which question.
Check a game key at server start
Know the key works before the first bet.
Updated