Roblox UtilitiesDevlHub Roblox Documentation

Friend referral system

Use referral links to track and reward players that have successfully invited other players into your game, and players that have joined your game using a referral link invitation from another player.

If you previously used this feature while it was still in beta, make sure to implement the new customized reward banners to maximize the reach of your friend referral system.

The friend referral system encourages existing players to bring new players into your game, increasing player retention and overall engagement. Players can access and share referral links from player invite prompts or directly from the default in-game invite menu.

As a developer, you can create customized banners to advertise your reward system and use shareable referral links to:

  • Track which players have successfully invited other players into your game.
  • Track which players have joined your game using a referral link invitation from another player.
  • Create and distribute rewards to both inviters and invitees.
Inviters send out invites
Invitees join the game

To implement a referral system, set up a referral event and create referral rewards in Studio. The ReferredByPlayerId property of GetJoinData() automatically populates for all types of invitations and gives you access to the user ID of the referring player. You can then access this data in the Players.PlayerAdded event to identify the inviter and grant rewards to both the inviter and the invitee.

Luau
function onPlayerAdded(player)

    local referredByPlayerId = player:GetJoinData().ReferredByPlayerId

    local referrerEvent: RemoteEvent = ReplicatedStorage:FindFirstChild("ReferralReceivedEvent")
    referrerEvent:FireClient(player, referredByPlayerId)
end

Players.PlayerAdded:Connect(onPlayerAdded)

To make sure that players understand the reward system, implement a customized reward banner at the top of your friend invite modal showing them details about the rewards they can earn.

Set up a referral event#

To set up a referral event:

  1. Set up a RemoteEvent in ReplicatedStorage to create a remote event to communicate with the client when a referral is received.
  2. Retrieve the inviter's user ID using ReferredByPlayerId to track player joins and handle the referral logic in your server-side script during the Players.PlayerAdded event.
Luau
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Create or get the RemoteEvent for handling referrals
local referrerEvent: RemoteEvent = ReplicatedStorage:FindFirstChild("ReferralReceivedEvent")

-- Function that triggers when a player joins
function onPlayerAdded(player)
    local joinData = player:GetJoinData()
    local referredByPlayerId = joinData.ReferredByPlayerId

    -- Check if the player was invited through a referral
    if referredByPlayerId and referredByPlayerId ~= 0 then
        -- Fire the referral event to the client, passing the inviter's ID
        referrerEvent:FireClient(player, referredByPlayerId)

        -- Additional logic for rewarding inviter and invitee can be added here
        -- e.g., rewardReferrer(referredByPlayerId)
        -- e.g., rewardInvitee(player)
    end
end

-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

Grant referral rewards#

To encourage participation, grant rewards to both inviters and invitees. For example, you can give inviters a badge or in-game currency when their friend joins the game, and give invitees a welcome reward for joining the game through a referral link.

Luau
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Create or get the RemoteEvent for handling referrals
local referrerEvent: RemoteEvent = ReplicatedStorage:FindFirstChild("ReferralReceivedEvent")

-- Function that triggers when a player joins
function onPlayerAdded(player)
    local joinData = player:GetJoinData()
    local referredByPlayerId = joinData.ReferredByPlayerId

    -- Check if the player was invited through a referral
    if referredByPlayerId and referredByPlayerId ~= 0 then
        -- Fire the referral event to the client, passing the inviter's ID
        referrerEvent:FireClient(player, referredByPlayerId)

        -- Reward the inviter
        function rewardReferrer(referrerId)
          local referrerPlayer = Players:GetPlayerByUserId(referrerId)
          if referrerPlayer then
              -- Grant the inviter their reward
              -- Example: referrerPlayer.leaderstats.Coins.Value += 100
          end
        end

        -- Reward the invitee
        function rewardInvitee(player)
            -- Grant the invitee their reward
            -- Example: player.leaderstats.WelcomeBonus.Value += 50
        end
    end
end

-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

Create a reward banner#

Reward banners encourage users to invite friends to join your game by showing them details about the referral rewards they can earn. These banners are displayed at the top of your friend invite modal.

To create a customized reward banner:

  1. In the Creator Hub, go to Creations and select the game that you have set up a referral event for.
  2. Go to Engagement ⟩ Referral Rewards.
  3. Click Add Reward Details.
  4. In the Referral Rewards page:
    1. Replace the default icon with an image that represents your game.
    2. Enter a reward name to display on the banner.
    3. Select a start and end date for when you want to show the banner to players.
    4. OPTIONAL Enter a description with details about the reward.
    5. OPTIONAL If you want to add reward restrictions, enter a reward limit. For example, a limit of up to 3 rewards per inviter.
  5. Click Save to save your changes.
  6. Click Publish to make the banner visible to players.

You can create many different banners, but only one banner can be published and shown at a time. Make sure that the published banner accurately describes the referral system you have implemented in Studio.