A Guide to Providing Benefits to Roblox Premium Members for your Game

A Guide to Providing Benefits for Roblox Premium Members


I figured it would be nice to show others some ways you could give Roblox Premium Members in-game benefits for your game.

Some of you will probably know these methods, but this is a tutorial for those who don’t.

This tutorial assumes you know the basics of Roblox Luau scripting.


An Explanation on how Developers Give Benefits to Premium Members

There’s a specific method that all scripters use in order to give only Roblox Premium Members the benefits:

if player.MembershipType == Enum.MembershipType.Premium then
   -- Give Benefits here
end

The code above checks if the player has a Premium, and gives the benefit. If the Player does not have Premium, then the player will not receive the benefit.

You can read more about checking if a player has Premium here.

If you want to prompt the player to buy Premium if they don’t have it, then use the PromptPremiumPurchase Method:

game:GetService("MarketplaceService"):PromptPremiumPurchase(player)

You can read more about PromptPremiumPurchase here.

Let’s the say a player bought Premium with the PromptPremiumPurchase Modal, and you want to apply the Benefit to them as soon as they purchase it.

You’ll need to use an event called PlayerMembershipChanged, which detects when a
the player’s membership has changed to Premium.

Like so:

game:GetService("Players").PlayerMembershipChanged:Connect(function(player)
  -- Give benefits
end)

You can read more about the PlayerMembershipChanged event here.

Now that you know how the API works, let’s get into the different ways you can give benefits to Premium Members


Benefit 1: Chat Tag (ChatService)

If you are unfamiliar with ChatService, I suggest you take a look at this article.

Let’s start by creating a Server Script, preferably in ServerScriptService.

Now, we’ll want to require ChatService Module Script so we can make the Chat Tags. We’ll need to use :WaitForChild, since the ModuleScript will only appear in-game.

local Players = game:GetService("Players") -- We'll need this later
local ServerScriptService = game:GetService("ServerScriptService") -- Where the ModuleScript is Located
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

Great!

Now we’ll need to create a function that detects when a speaker is added to the chat, using the SpeakerAdded Event.

Like this:

local function onSpeakerAdded(speakerName)

end

ChatService.SpeakerAdded:Connect(onSpeakerAdded) -- Connecting the SpeakerAdded event to the onSpeakerAdded function

Now we’ll need to get the speaker that joined:

local function onSpeakerAdded(speakerName)
   local Speaker = ChatService:GetSpeaker(speakerName) -- Gets the Speaker in the Server
   local Player = Players:FindFirstChild(speakerName) -- Gets the Player in the server
end

ChatService.SpeakerAdded:Connect(onSpeakerAdded)

Now comes the part where we check to use if the player has Roblox Premium, and adding the Chat Tag if they do:



local function onSpeakerAdded(speakerName)
   local Speaker = ChatService:GetSpeaker(speakerName) -- Gets the Speaker in the Server
   local Player = Players:FindFirstChild(speakerName) -- Gets the Player in the server

   if player.MembershipType = Enum.MembershipType.Premium then 
      Speaker:SetExtraData("Tags", {{ -- Adds the Tag to the Player
			TagText = "Premium", -- Tag Name
			TagColor = Color3.fromRGB(255, 255, 255) -- Tag Color	(Change this to whatever color you want)
		}})
   end
end

ChatService.SpeakerAdded:Connect(onSpeakerAdded)

for _, Speaker in ipairs(ChatService:GetSpeakerList()) do -- Applies the Function to every speaker (player) in the server.
	speakerAdded(Speaker)
end

And its as simple as that! Simply Play Test in Studio, and if you have Premium, you should see something like this:

image


Final Code:

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local function onSpeakerAdded(speakerName)
    local function onSpeakerAdded(speakerName)
    local Speaker = ChatService:GetSpeaker(speakerName) -- Gets the Speaker in the Server
    local Player = Players:FindFirstChild(speakerName) -- Gets the Player in the server

   if player.MembershipType = Enum.MembershipType.Premium then 
      Speaker:SetExtraData("Tags", {{ -- Adds the Tag to the Player
			TagText = "Premium", -- Tag Name
			TagColor = Color3.fromRGB(255, 255, 255) -- Tag Color	(Change this to whatever color you want)
		}})
    end
  end

ChatService.SpeakerAdded:Connect(onSpeakerAdded)

for _, Speaker in ipairs(ChatService:GetSpeakerList()) do -- Applies the Function to every speaker (player) in the server.
	speakerAdded(Speaker)
end

Benefit 2: Chat Tag (TextChatService)

Note: Method 1 was about ChatService. This Method is for the new TextChatService.

For TextChatService, we’ll need to use Attributes in order for Premium Members to get Chat Tags.

First we’ll need to make a Server Script. We won’t need to require ChatService in the Script this time, given that TextChatService is a Service we can define using :GetService.


local TextChatService = game:GetService("TextChatService")

Great! Now we’ll need to use the PlayerAdded Event, so we can apply the attribute when a Roblox Premium Member joins the game.


local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

end)

Now we can check if player has Roblox Premium, and set the Attribute to the player if they do:

We’ll be using pcall, so if the code were to error, it would print a status code in the output.

Read more about pcalls here.


local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

   local s, hasPremium = pcall(function() -- We're using a pcall just in
		return player.MembershipType == Enum.MembershipType.Premium
   end)

   if s then -- If the player has Roblox Premium
      player:SetAttribute("isPremium", hasPremium) -- set the Attribute
   end

end)

Great! We've set the Attribute! Now we'll need to exit the Server script, and create a local script in StarterPlayerScripts to apply the Chat Tag.

Just like the last script, we’ll define our Services and use the TextChatService.InComingMessage to detect when a player is about to send a message:

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
 
end

Now we’ll need to create a new Instance called “TextChatMessageProperties” so we can apply the Chat Tag to every message the Premium Member sends:

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
    local properties = Instance.new("TextChatMessageProperties")

    return properties
end

<b
Now we check if the player has the isPremium attribute we set earlier. If they do, we give them the chat tag.

(Note that “TextSource” is basically the same thing as “Speaker” for ChatService.)


local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
    local properties = Instance.new("TextChatMessageProperties")

    if message.TextSource then -- if the TextSource/Speaker exists then
        local player = Players:GetPlayerByUserId(message.TextSource.UserId) -- Get the player from the TextSource/Speaker
        if player:GetAttribute("isPremium") then -- if the player has the attribute then
            properties.PrefixText = "<font color='#FFFFF'>[Premium]</font>" ..  message.PrefixText -- set the Chat Tag (set the hex color to whatever you want)
        end
    end

    return properties
end

And its as simple as that!

You should see something like this:
image


Final Code:

Server Script (ServerScriptService):

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

	local s, hasPremium = pcall(function() -- We're using a pcall just in
		return player.MembershipType == Enum.MembershipType.Premium
	end)

	if s then -- If the player has Roblox Premium
		player:SetAttribute("isPremium", hasPremium) -- set the Attribute
	end

end)

Local Script (StarterPlayerScripts):

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then -- if the TextSource/Speaker exists then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId) -- Get the player from the TextSource/Speaker
		if player:GetAttribute("isPremium") then -- if the player has the attribute then
			properties.PrefixText = "<font color='#FFFFFF'>[Premium]</font> " .. message.PrefixText
		end
	end

	return properties
end

Benefit 3: Exclusive Tool

Let’s say you wanted Premium Members to get an exclusive tool or weapon for their game.

Let’s start by defining a variable for where the tool is located in explorer.

For this example, we’ll assume that the Tool is ServerStorage:
image


local ReplicatedStorage = game:GetService("ServerStorage")
local Tool = ServerStorage.Tool

Great! Now its time to add the PlayerAdded, so we can give the Premium Member the benefit when they join:
local ReplicatedStorage = game:GetService("ServerStorage")
local Tool = ServerStorage.Tool
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player: Player)
     
end)

Now we’ll have to clone the tool from ReplicatedStorage, and place the cloned tool into the player’s Backpack.

local ReplicatedStorage = game:GetService("ServerStorage")
local Tool = ServerStorage.Tool
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player: Player)
    if player.MembershipType == Enum.MembershipType.Premium then
        local toolClone = Tool:Clone()
          toolClone.Parent = player.Backpack
    end
end)

Great! Now when a Premium Member joins the game, they will receive the tool.

What if you wanted to give the Premium Member the tool if they bought Premium in game?

We’ll use the Player.MembershipChanged Event I mentioned earlier:

local ReplicatedStorage = game:GetService("ServerStorage")
local Tool = ServerStorage.Tool
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player: Player)
    if player.MembershipType == Enum.MembershipType.Premium then
        local toolClone = Tool:Clone()
          toolClone.Parent = player.Backpack
    end
end)

Players.MembershipChanged:Connect(function(player)
     local toolClone = Tool:Clone()
     toolClone.Parent = player.Backpack
end)

And that's it! When a Roblox Premium Member joins the game, they will receive the tool. And if they bought Premium in-game, they will also receive the tool.

Benefit 4: A Badge

For this Section of the tutorial, I will assume you already have a badge created.

First, we’ll need to create a script, preferably in ServerScriptService, and then define our services.

We’ll be using BadgeService.


local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

Now, let’s make a variable for our badge id.

Simply go to the page of your badge and copy the ID found in the URL:

image


local Players = game:GetService("Players")
local BadgeService = game:GetService("Players")

local badgeId = 2128188347 -- This is the id for the badge I'm using. Replace it with your own.

Now we’ll make a function that will award the badge to the player if they are a Premium Member.

local Players = game:GetService("Players")
local BadgeService = game:GetService("Players")

local badgeId = 2128188347

local function awardBadge(player : Player, badgeId)

end

First, we’ll fetch the badge’s information so we’ll be able to determine whether the Badge is enabled or not:


local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local badgeId = 00000000

local function awardBadge(player, badgeId)

	local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
	if success then
		
		if badgeInfo.IsEnabled then
		     
		end
	else
		warn("Error while fetching badge info!")
	end
end


Now, we’ll check if the player has Premium, and if they do, we’ll award the badge:


local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local badgeId = 00000000

local function awardPremiumBadge(player, badgeId)

	local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
	if success then
		
		if badgeInfo.IsEnabled then
		     if player.MembershipType == Enum.MembershipType.Premium then
                 local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, player.UserId, badgeId)
                 if not awarded then
                    warn("Error while awarding badge:", errorMessage)
                 end
             end
		end
	else
		warn("Error while fetching badge info!")
	end
end

Now we’ll create a function called “onPlayerAdded” that will award the Premium Member the badge when they join the game.


local function onPlayerAdded(player)
  -
end

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

Now we’ll check if the player owns the badge. If they do own the badge, we won’t give them the badge. If they don’t own the badge, we will award the badge to them.


local function onPlayerAdded(player: Player)

	local success, hasBadge = pcall(BadgeService.UserHasBadgeAsync, BadgeService, player.UserId, badgeID)

	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if not hasBadge then
		awardPremiumBadge(player, badgeId)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Great! Premium members will now earn the badge if they haven’t already. There’s one more thing we’ll need to do though. If a player were to buy Premium in game, we’ll have to give them the badge when they buy it.

We’ll use the same method we did with the Exclusive Tool Script (Player.MembershipChanged).


Players.MembershipChanged:Connect(function(player)
   awardPremiumBadge(player, badgeId)
end)

And that’s it!

Final code:


local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local badgeId = 0000000

local function awardPremiumBadge(player: Player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, player.UserId, badgeId)
			if not awarded then
				warn("Error while awarding badge:", errorMessage)
			end
		end
	else
		warn("Error while fetching badge info!")
	end
end

local function onPlayerAdded(player: Player)

	local success, hasBadge = pcall(BadgeService.UserHasBadgeAsync, BadgeService, player.UserId, badgeId)

	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if not hasBadge then
		awardPremiumBadge(player, badgeId)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)


Benefit 5: Extra Health

This one is actually very simple.

When the player joins, we will detect if the player has premium and then give them extra max health.

First, we’ll created a Server Script, preferably in ServerScriptService, and start by defining our services and then adding the PlayerAdded Event to detect when a player joins:


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
      
     
end)

Now, we’ll do the character added event since a character is required to be able to change a player’s health at all.


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
	end)
	
end)

Now we’ll definite out variable for the player’s Humanoid, which is where we will be changing the health of the player.


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		local Humanoid = character and character.Humanoid and character:FindFirstChildOfClass("Humanoid")
		
	end)
	
end)

Now it’s time that we detect if a player is premium, and then set increase max health and health. In this tutorial, we will be increasing the health by 50.


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		local Humanoid: Humanoid = character:WaitForChild("Humanoid") -- Defining the character's Humanoid with Type Checking
		 
       if Humanoid then -- If the humanoid exists then
		
		local success, ownsPremium = pcall(function()
			return player.MembershipType == Enum.MembershipType.Premium
		end)
		
		if success then
			if ownsPremium then -- If the player owns Premium then
				Humanoid.MaxHealth = 150 -- Set the player's Max Health to 150
				Humanoid.Health = Humanoid.MaxHealth -- Set the player's Health to it's Max Health
			end
		end
	end
end)
	
end)

And that’s it!

Premium Players should now have 50+ extra health. :slight_smile:

Final Code:


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
			
		local success, ownsPremium = pcall(function()
			return player.MembershipType == Enum.MembershipType.Premium
		end)
		
		if success then
			if ownsPremium then
				local Humanoid: Humanoid = character:WaitForChild("Humanoid")
				Humanoid.MaxHealth = 150
				Humanoid.Health = Humanoid.MaxHealth
			end
		
		end
		
	end)
	
end)


If there are any other Premium Benefits would be good to add to this tutorial or if you have any feedback for this tutorial, please let me know in the replies. :slight_smile:

I hope this helped you.

Thanks to @XionKazdok for giving me courage to make a Tutorial on the DevForum.


My Other Tutorial and Resource

A List of All Deprecated Classes, Enums, Events, Functions, and Properties

How to look at the Source-Code of any Roblox Website Extension (without downloading it)

Edit: Fixed a Typo in the Code for benefit 3, and modified the tool placement example for Benefit 3.
Edit 2: Added Benefit 4.
Edit 3: Typo Fix
Edit 4: Added Benefit 5

15 Likes

Glad you asked

Premium lounge where only premium members can go inside
(Premium players go through part)

As in a Premium-Only door?

I would put it in serverstorage because replicatedstorage is risky and you can clone it into your starter gear (yes tools are vulnerable)

you forgot the double equals

3 Likes

Thanks for the feedback and for pointing out the typo. I’ve updated the tutorial with your suggestions.

1 Like

Yes, like a door that lets only premium members go through, non collidable
But for regular users its collidable

1 Like

Cool tutorial. Here are some more ideas:
-Double money/any stat.
-Unique Badge.

I am sure there are more ideas.

1 Like

Great ideas. I will add them when I can :slightly_smiling_face:

local janitor = require(path.to.janitor)
local plrConnections = janitor.new()
local collisionService = game:GetService("PhysicsService")
collisionService:CreateCollisionGroup("premiumAreas")
collisionService:CollisionGroupSetCollidable("premiumAreas", "premiumAreas", false)
collisionService:CollisionGroupSetCollidable("Default", "premiumAreas", true)
local premiumWalls = {}
for _,v in premiumWalls do
   collisionService:SetPartCollisionGroup(v, "premiumAreas")
end
game.Players.PlayerAdded:Connect(function(plr)
   if plr.MembershipType == Enum.MembershipType.Premium then
      plrConnections:Add(plr.CharacterAdded:Connect(function(char)
      for _,v in char:GetChildren() do
         if v:IsA("BasePart") then
            collisionService:SetPartCollisionGroup(v, "premiumAreas")
         end
      end
   end, "Disconnect", "plr_"..plr.UserId)
end)
game.Players.PlayerRemoving:Connect(function(plr)
   plrConnections:Remove("plr_"..plr.UserId)
end)

untested but should look something like this.
used janitor so that i can easily remove character connections

2 Likes

This tutorial is meant for beginners, and I don’t believe any beginners will understand how to use or understand Janitor yet, so its best to make a script without it.

1 Like

I added the badge :slight_smile:

I considered adding that, but I didn’t do it for 2 reasons:

  1. Every game has a different use case for using leaderstats, so it would be hard to make a specific example that would be useful for everyone.

  2. A bit too pay to win

1 Like

Great to see you making a tutorial mate, keep it up.

No need to thank me, it’s all you.
Cheers.

1 Like

Added Another Section that explains how to give Premium Players Extra Health (Benefit 5).