Skip to content

Configuration Types ​

Enhanced Profile Configuration ​

lua
type ProfileConfig = {
    Key: string,        -- Base key for ProfileStore
    Template: PlayerData, -- Default data template
    GlobalUpdates: boolean, -- Enable global updates
}

Enhanced DataStore Configuration ​

lua
type DataStoreConfig = {
    Name: string,       -- DataStore name
    Scope: "Production" | "Testing", -- Environment scope
}

Complete Configuration with New Options ​

lua
type PlayerStateConfig = {
    Profile: ProfileConfig,
    DataStore: DataStoreConfig,
    CleanExtraFields: boolean,  -- Remove fields not in template during reconciliation
    DataWaitTimeout: number,    -- Seconds to wait for player data before timeout
    BatchDelay: number,         -- Batch processing delay in seconds
    BatchSize: number,          -- Auto-flush batch when this many operations are queued
    MaxCacheSize: number,       -- Maximum number of cached path keys
    RuntimeNonPersistentRoots: {string}, -- Replicated but never saved (e.g. session)
    ServerOnlyRoots: {string},           -- Saved but stripped before player Replica
    SharedSession: {[string]: any},     -- Template for server-wide shared session (no nested Template)
    Leaderboard: {              -- Leaderboard configuration
        Enabled: boolean,           -- Enable/disable leaderboard functionality
        DataStoreName: string,      -- DataStore for leaderboard data
        TrackedStats: {string},     -- Stats to track on leaderboards
        SyncInterval: number,       -- Leaderboard sync frequency in seconds
        UpdateOnPlayerLeave: boolean, -- Update leaderboards when players leave
    },
}

Default Configuration:

lua
-- PlayerStateConfig.lua
local Config = {
    Server = {
        Profile = {
            Key = "PlayerData",
            Template = DefaultData,
        },
        DataStore = {
            Name = "PlayerData_0.01",
            Scope = "Production",
        },
        CleanExtraFields = false,
        DataWaitTimeout = 10,
        BatchDelay = 0.03,      -- 30ms batch delay
        BatchSize = 20,         -- Auto-flush at 20 operations
        MaxCacheSize = 1000,    -- Maximum cache entries

        RuntimeNonPersistentRoots = {
            "session",
            "_LeaderboardRanks",
            "_Leaderboards",
            "_Leaderboard",
        },

        ServerOnlyRoots = {
            "Server",
        },

        SharedSession = {},

        Leaderboard = {
            Enabled = true,
            DataStoreName = "PlayerState_Leaderboards",
            TrackedStats = {
                "Gems",
                "Coins",
                -- Add stat names here to create leaderboards
            },
            SyncInterval = 60,
            UpdateOnPlayerLeave = true,
        },
    },
    Client = {
        CacheDuration = 0.1,
        CacheCleanupInterval = 30,
        MaxCacheSize = 1000,
        MaxPathCacheSize = 1000,
    },
}

PlayerState - High-Performance Roblox Data Management