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:
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:
Final Code:
Server Script (ServerScriptService):
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local success, hasPremium = pcall(function() -- We're using a pcall just in
return player.MembershipType == Enum.MembershipType.Premium
end)
if success 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:
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:
local Players = game:GetService("Players")
local BadgeService = game:GetService("Players")
local badgeId = 00000000 -- Replace this with the id of the badge you're awarding to the Premium Players
Now we’ll make a function that will award the badge to the player.
local Players = game:GetService("Players")
local BadgeService = game:GetService("Players")
local badgeId = 00000000
local function awardBadge(player : Player, id)
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, id)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, id)
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 awardBadge(player: Player, id)
-- Fetch badge information
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, id)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, player.UserId, id)
if not awarded then
warn("Error while awarding badge:", errorMessage)
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
if player.MembershipType == Enum.MembershipType.Premium then -- Check if the player has Premium
awardBadge(player, badgeId)
end
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)
awardBadge(player, badgeId)
end)
And that’s it!
Final code:
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeId = 00000000
local function awardBadge(player: Player, id)
-- Fetch badge information
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, id)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, player.UserId, id)
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
if player.MembershipType == Enum.MembershipType.Premium then
awardBadge(player, badgeId)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.MembershipChanged:Connect(function(player)
awardBadge(player, badgeId)
end)
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.
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)
Benefit 6: Double Walkspeed
For this benefit, we will giving Roblox Premium owns 2x the amount of WalkSpeed.
First, we’ll start by make a Server Script, preferably in ServerScriptService, define our services, and add the PlayerAdded and Character Added Event.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
end)
end)
Now we will define the player’s Humanoid as a variable, and then check if a player owns Premium. If they do, we give them double the amount of the default walkspeed (which is 26).
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local Humanoid = character:FindFirstChildOfClass("Humanoid")-- Humanoid Variable
local success, result = pcall(function() -- A pcall
return player.MembershipType == Enum.MembershipType.Premium
end)
if success then
if result then -- if the player owns Premium then
Humanoid.WalkSpeed *= 2 -- Double the Premium Player's walkspeed
else
warn(result) -- If the player does not own the gamepass
end
else
error("Error when attempting to receive Premium Status")
end
end)
end)
And that’s it! If the player has Premium, they will have double the amount of the usual walkspeed.
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.
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 in 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
Edit 5: Added Benefit 6
Edit 6: Fixed Benefit 4.
Edit 7: Actually Fixed Benefit 4