Skip to main content

PlayerProfileManager

This item only works when running on the server. Server

This class is responsible for managing player profiles. It is a singleton class, so calling PlayerProfileManager.new multiple times will return the same instance. It is recommended to create a PlayerDataService to manage this class.

Types

DataMigrator

interface DataMigrator {
FromVersionstring
ToVersionstring
Migrate(
profileDatatable,
profileOwnerPlayer
) → (table)
}

Config

interface Config {
DataStoreKeystring
DefaultDataSchematable
UseMockboolean?
Migrator{DataMigrator}
GetPlayerKeyCallback((playerPlayer) → (string))?
ReconcileCallback((
playerPlayer,
profileProfile
) → ())?
OnProfileLoadFailure((
playerPlayer,
errstring
) → ())?
}

OnProfileLoadFailure callback will default to kicking the player if not provided.

Functions

new

PlayerProfileManager.new(configConfig) → PlayerProfileManager

Creates a new PlayerProfileManager. This is a singleton class, so calling this function multiple times will return the same instance. Takes a config table with the following fields.

PlayerProfileManager.new({
    DataStoreKey = "PlayerData";
    DefaultDataSchema = {
        __VERSION = "0.0.0";
        Currency = 0;
    };
})

IsLoaded

PlayerProfileManager:IsLoaded(playerPlayer) → boolean

Returns whether or not the player's profile is currently loaded.

local isLoaded = PlayerProfileManager:IsLoaded(player)

OnLoaded

PlayerProfileManager:OnLoaded(playerPlayer) → Promise<()>

Returns a promise that will resolve when the player's profile is loaded. Rejects if the player leaves or the profile fails to load.

PlayerProfileManager:OnLoaded(player):andThen(function()
    print("Profile loaded for " .. player.Name)
end)

GetProfile

PlayerProfileManager:GetProfile(playerPlayer) → Profile?

Returns the player's profile, if it exists. May return nil if this players profile is not loaded.

local profile: Profile? = PlayerProfileManager:GetProfile(player)

PromiseProfile

PlayerProfileManager:PromiseProfile(playerPlayer) → Promise<Profile>

Returns a promise that resolves with the player's profile when it is ready. Rejects if the player leaves or the profile fails to load.

PlayerProfileManager:PromiseProfile(player):andThen(function(profile: Profile)
    print("Profile loaded for " .. player.Name)
end)
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new PlayerProfileManager. This is a singleton class, so calling this function multiple\ntimes will return the same instance. Takes a config table with the following fields.\n\n```lua\nPlayerProfileManager.new({\n    DataStoreKey = \"PlayerData\";\n    DefaultDataSchema = {\n        __VERSION = \"0.0.0\";\n        Currency = 0;\n    };\n})\n```",
            "params": [
                {
                    "name": "config",
                    "desc": "",
                    "lua_type": "Config"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "PlayerProfileManager\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 100,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_reconcileProfile",
            "desc": "",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "profile",
                    "desc": "",
                    "lua_type": "Profile"
                }
            ],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 145,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_lookupMigrator",
            "desc": "Looks up a migrator function for a specific version",
            "params": [
                {
                    "name": "fromVersion",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DataMigrator?\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 157,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_migrateProfileData",
            "desc": "Attempts to migrate the player's profile data to the latest version.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "profile",
                    "desc": "",
                    "lua_type": "Profile"
                }
            ],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 175,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_generatePlayerKey",
            "desc": "Generates a key for the player based on the GetPlayerKeyCallback if it exists.",
            "params": [
                {
                    "name": "playerOrUserId",
                    "desc": "",
                    "lua_type": "Player | number | string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 222,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_attemptLoadProfile",
            "desc": "Attempts to load the profile for the given player asyncronously.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 234,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_createPlayerData",
            "desc": "",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 269,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_PromisePlayerLoadEventFailure",
            "desc": "Generates a promise that will reject when the player leaves or the profile fails to load.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 323,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "_PromisePlayerLoadEventSuccess",
            "desc": "Generates a promise that will resolve when the player's profile is loaded.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 335,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "IsLoaded",
            "desc": "Returns whether or not the player's profile is currently loaded.\n\n```lua\nlocal isLoaded = PlayerProfileManager:IsLoaded(player)\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 353,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "OnLoaded",
            "desc": "Returns a promise that will resolve when the player's profile is loaded.\nRejects if the player leaves or the profile fails to load.\n\n```lua\nPlayerProfileManager:OnLoaded(player):andThen(function()\n    print(\"Profile loaded for \" .. player.Name)\nend)\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<()>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 370,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "WipeProfile",
            "desc": "THIS METHOD IS UNFINISHED AND CURRENTLY CAUSES ERRORS.\nWipes the player's profile from the data store.\nUse this in cases where you need to reset a player's data or\ncomply with a right to erasure request.",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\n"
                }
            ],
            "function_type": "method",
            "private": true,
            "unreleased": true,
            "source": {
                "line": 389,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "GetProfile",
            "desc": "Returns the player's profile, if it exists. May return nil if this players profile is not loaded.\n\n```lua\nlocal profile: Profile? = PlayerProfileManager:GetProfile(player)\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Profile?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 425,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "PromiseProfile",
            "desc": "Returns a promise that resolves with the player's profile when it is ready.\nRejects if the player leaves or the profile fails to load.\n\n```lua\nPlayerProfileManager:PromiseProfile(player):andThen(function(profile: Profile)\n    print(\"Profile loaded for \" .. player.Name)\nend)\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Profile>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 443,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "DataMigrator",
            "desc": "",
            "fields": [
                {
                    "name": "FromVersion",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "ToVersion",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Migrate",
                    "lua_type": "(profileData: table, profileOwner: Player) -> (table)",
                    "desc": ""
                }
            ],
            "source": {
                "line": 37,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        },
        {
            "name": "Config",
            "desc": "OnProfileLoadFailure callback will default to kicking the player if not provided.",
            "fields": [
                {
                    "name": "DataStoreKey",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "DefaultDataSchema",
                    "lua_type": "table",
                    "desc": ""
                },
                {
                    "name": "UseMock",
                    "lua_type": "boolean?",
                    "desc": ""
                },
                {
                    "name": "Migrator",
                    "lua_type": "{DataMigrator}",
                    "desc": ""
                },
                {
                    "name": "GetPlayerKeyCallback",
                    "lua_type": "((player: Player) -> (string))?",
                    "desc": ""
                },
                {
                    "name": "ReconcileCallback",
                    "lua_type": "((player: Player, profile: Profile) -> ())?",
                    "desc": ""
                },
                {
                    "name": "OnProfileLoadFailure",
                    "lua_type": "((player: Player, err: string) -> ())?",
                    "desc": ""
                }
            ],
            "source": {
                "line": 71,
                "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
            }
        }
    ],
    "name": "PlayerProfileManager",
    "desc": "This class is responsible for managing player profiles. It is a singleton class, so calling\n`PlayerProfileManager.new` multiple times will return the same instance. It is recommended to\ncreate a `PlayerDataService` to manage this class.",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 12,
        "path": "src/playerprofilemanager/src/Server/PlayerProfileManager.lua"
    }
}