PlayFab SDK | Unlock the full power of PlayFab on Roblox!

PlayFab SDK

A PlayFab SDK for Roblox written in TypeScript (with a Lua counterpart).

GitHub - NPM

Introduction

This is a module for interfacing with all PlayFab APIs and services that are relevant and/or usable on Roblox. It has been written with TypeScript (using Roblox-TS) and is specifically designed for Roblox-TS users because of the benefits TypeScript brings. However, @pobammer has created a less scary fix-up of the compiled Lua code for any Lua users that wish to use this.

The entire PlayFab API is typed (using typings from the official Node SDK) and all methods have a basic explanation with links to the relevant API references on the PlayFab docs (only with TypeScript).


Usage

This SDK follows an identical pattern to all other PlayFab SDKs which means that once you have a basic understanding of this SDKs usage you can easily follow all official PlayFab documentation like any other PlayFab SDK.

Before anything, you need to set the TitleId and Secret in the settings. If you are unsure of where to find your TitleId then please refer to this tutorial or this one for the Secret.

TypeScript:

import { Settings } from '@rbxts/playfab'

Settings.settings.titleId = 'TITLE_ID'
Settings.settings.secretKey = 'SECRET_KEY'

Lua:

local PlayFab = require(path.to.PlayFab)
local Settings = PlayFab.Settings

Settings.settings.titleId = 'TITLE_ID'
Settings.settings.secretKey = 'SECRET_KEY'

Once you have set those you are free to use all methods! One important thing to note is that many PlayFab APIs are designed to run on the client. Obviously on Roblox this is not possible because HttpService is only accessible on the server.

I got around this issue by making all methods that are designed to run on the client take a player argument. Before using any of these methods, you must log the client in using ClientApi.LoginWithCustomID.

TypeScript:

import { Players } from '@rbxts/services'
import { Settings, ClientApi } from '@rbxts/playfab'

Settings.settings.titleId = 'TITLE_ID'
Settings.settings.secretKey = 'SECRET_KEY'

Players.PlayerAdded.Connect(async player => {
    // Log client in
    // This must be async and no client-side methods can be used until this has returned.
    await ClientApi.LoginWithCustomID(player, {
        CreateAccount: true, // Create an account if one doesnt already exist
        CustomId: tostring(player.UserId) // You can use your own CustomId scheme
    })

    // You are ready to go!
    const profile = await ClientApi.GetPlayerProfile(player, {})
    
    if (profile.PlayerProfile) {
        print(profile.PlayerProfile.PlayerId)
    }
})

Lua:

local PlayFab = require(script.Parent.playfab)
local Settings = PlayFab.Settings
local Client = PlayFab.ClientApi

Settings.settings.titleId = 'TITLE_ID'
Settings.settings.secretKey = 'SECRET_KEY'

game.Players.PlayerAdded:Connect(function(player)
    -- Log client in
    -- This must be async and no "client-side" methods can be used until this has returned.
    Client.LoginWithCustomID(player, {
        CreateAccount = true, -- Create an account if one doesn't already exist
        CustomId = tostring(player.UserId) -- You can use your own CustomId scheme
    }):andThen(function()
        -- You are ready to go!
        Client.GetPlayerProfile(player, {}):andThen(function(profile)
            if (profile.PlayerProfile) then
                print(profile.PlayerProfile.PlayerId)
            end
        end)
    end)
end)

APIs

This module covers all PlayFab APIs, excluding a few which are not usable on Roblox.

  • AdminApi
  • AuthenticationApi
  • ClientApi
  • DataApi
  • EventsApi
  • ExperimentationApi
  • GroupsApi
  • MultiplayerApi
  • ProfilesApi
  • ServerApi

In Action

Here’s a video of the SDK in action! Only shows a few methods but you get the idea.


Should you come across any missing or broken endpoints then please let me know or create a pull request with a potential solution!

Hopefully, some people get some use out of this module! It was torture to write :sweat_smile:

41 Likes

As someone who has tried Playfab-playfab and Roblox’s version of Playfab, the real deal is much better. It is quite an investment, but you will likely benefit strongly from it; not to mention the pricing being reasonable for what it is.

I highly suggest any professional developer use Playfab for storing their data, analytics, etc.!! Playfab is really powerful!!!

11 Likes

Thanks a lot for this. I trying to use it now in a new game i am developing!

3 Likes

Friendly update, the Lua release module seems to be broken a tad bit :sweat_smile:
image
Both titleId and secretKey are set.

2 Likes

Sorry about that, I haven’t made a release for Lua in a while.

Here you go!

1 Like

Still getting that same error
image
Even tried to manually set it in the settings table, but no avail.

2 Likes

Can you send your source code? It works fine for me:

local playfab = require(script.PlayFab)
playfab.Settings.titleId = "test"
1 Like

In the example sent for Lua, it’s structured like this:
image

1 Like

Oh, sorry! That’s how you accessed settings in v1.x of the SDK, it has since changed in v2.x. I have up-to-date examples on the repository.

1 Like

The docs at https://gril.me/RobloxPlayFabSDK/ seem to be gone. Is this still maintained?