Hello and welcome back to my tutorial on making a marketplace system.
Most games have special offers or advantages for when you get premium membership. We like to call them premium benefits.
For this tutorial, I will be showing you how to make premium benefits for your game.
STEP 1: What benefits will you make?
Premium benefits can be offered as a tool, access to a certain area, extra coins or XP, etc. It’s up to you to think about what you’re going to do, but let’s just stick with coins for this tutorial.
Now let’s think about how many coins you want to give the player…
- 10 Coins
- 25 Coins
- 50 Coins
- 75 Coins
- 100 Coins
And think about the time between the player will receive them…
- 1 Minute
- 2 Minutes
- 5 Minutes
Usually, I would do 50 coins every 2 minutes of playtime but you can pick any of the above!
STEP 2: Making the GUI
Now we’re gonna move on to the GUIs. Here’s how we’re gonna do it:
-
Create a new
ScreenGUI
inStarterGui
. -
Add a new
ImageButton
in your ScreenGui. Set the anchor point as 0.5, 0.5, resize it and position it to the bottom of your screen. -
Find a premium membership label for your image button. Make sure that it’s a PNG image.
So at the end, your button should look like this at the bottom of your screen:
Now, we’re gonna introduce the player to the premium benefits.
-
Add a
Frame
inside the same gui and name it, “Premium Benefits”. -
Set the same anchor point from earlier and this time, position the frame to the middle of the screen.
-
Resize the frame to fit your list of premium benefits.
-
Add
TextLabel
s for your benefits and another one for your title saying. “Premium Benefits”. Don’t forget to resize the text to make it visible to players. -
Add your
TextButton
at the bottom of the frame and another one for when you close the frame.
So in the end, the frame should look like this at the bottom of your screen:
Forgot to mention, you can set frame and text color to the color of your choice.
STEP 3: The scripts
Finally, you have reached everyone’s favorite part! Now to start off, make sure API services, third party sales and HTTP Requests are enabled.
How do I toggle these settings?
Game Settings > Security
The server script
Add a server script inside ServerScriptService
.
NOTE: If you have more than one script inside there, I highly recommend renaming them to avoid confusion.
Now follow what I do:
- Create a function for when a player joins the game.
game.Players.PlayerAdded:Connect(function(player)
-- stuff
end)
- Create the leaderstats.
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0
- Now we’re gonna check if the player joined with premium or not by using
player.MembershipType
. That’s anEnum
value which returns the type of membership the player has.
So add a conditional statement inside the function which will determine if the player has premium or not.
if player.MembershipType == Enum.MembershipType.Premium then
-- stuff
end
The possible memberships the player might have
There are currently four Enum.MembershipType
values (apart from None
which basically means that the player has no current membership):
Premium
-
BuildersClub
(Unobtainable) -
TurboBuildersClub
(Unobtainable) -
OutrageousBuildersClub
(Unobtainable)
Now, earlier in the tutorial, we made up a list of premium benefits to use. Again, let’s say the player will get 50 coins every 2 minutes of playtime. Therefore:
- Create a loop.
while wait(120) do -- 120 seconds for two minutes
-- stuff
end
And of course:
while wait(120) do
coins.Value += 50 -- 50 coins every two minutes
end
And, Voilà! Your server script should look like this:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0
if player.MembershipType == Enum.MembershipType.Premium then
while wait(120) do
coins.Value += 50
end
end
end)
The GUI script
Now let’s move on to the gui script. Add a LocalScript
in the premium benefit frame and follow these steps:
First, we’ll get our GUI components.
local Frame = script.Parent
local premiumButton = Frame.Premium -- The get-premium button
local openPremiumButton = Frame.Parent.OpenPremium -- The open-gui button outside the frame
local closePremiumButton = Frame.CloseShop -- The button to close the gui
Next, we’ll get the services needed and other variables.
local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local player = players.LocalPlayer
Just to make the frames invisible…
Frame.Visible = false
closePremiumButton.Visible = false
openPremiumButton.Visible = true
Now we’ll just need to make the frames visible for when openPremiumButton
is clicked.
openPremiumButton.MouseButton1Click:Connect(function()
Frame.Visible = true
closePremiumButton.Visible = true
end)
What we can also do
openPremiumButton.MouseButton1Click:Connect(function()
Frame.Visible = (not Frame.Visible) -- An easier way to toggle a boolean by assigning it to its opposite
closePremiumButton.Visible = (not closePremiumButton.Visible)
end)
not Button.Visible
can be used if you want to click the same button to open or close a GUI element because .Visible
is a boolean value.
Now for the premiumButton
, we’ll prompt the player to buy premium. Therefore, we’ll use MarketplaceService:PromptPremiumPurchase(Player)
.
premiumButton.MouseButton1Click:Connect(function()
--[[ -- optional line --
if player.MembershipType == Enum.MembershipType.Premium then
print("You already have Premium!")
end
]]
mps:PromptPremiumPurchase(player)
end)
And to close the frame:
closePremiumButton.MouseButton1Click:Connect(function()
Frame.Visible = false
closePremiumButton.Visible = false
end)
The finished code:
GUI local script
local Frame = script.Parent
local premiumButton = Frame.Premium
local openPremiumButton = Frame.Parent.OpenPremium
local closePremiumButton = Frame.CloseShop
local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local player = players.LocalPlayer
Frame.Visible = false
closePremiumButton.Visible = false
openPremiumButton.Visible = true
openPremiumButton.MouseButton1Click:Connect(function()
Frame.Visible = true
closePremiumButton.Visible = true
end)
premiumButton.MouseButton1Click:Connect(function()
--[[ -- optional line --
if player.MembershipType == Enum.MembershipType.Premium then
print("You already have Premium!")
end
]]
mps:PromptPremiumPurchase(player)
end)
closePremiumButton.MouseButton1Click:Connect(function()
Frame.Visible = false
closePremiumButton.Visible = false
end)
Server script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0
if player.MembershipType == Enum.MembershipType.Premium then
while wait(120) do
coins.Value += 50
end
end
end)
Thanks for reading!
If you have any problems or if I miss anything in this topic, feel free to reply and I’ll be happy to edit. Again, thank you for reading! Good luck!
Was this helpful?
- Yes it was! Thank you.
- Nah. I already knew that
0 voters