MarketplaceService
This service is basically used for in-game purchase/transaction. Can be used for gamepass purchase, developer product purchase, getting product/asset info, etc
Important Functions/Events
1. PromptGamePassPurchase
This function is used to prompt/show a user a gamepass transaction tab with the given id and it's normally used in LocalScript
Paremeters: player, gamePassId
Example Code:
local MPS = game:GetService("MarketplaceService")
local gamePassId = 123
local player = game.Players.LocalPlayer
MPS:PromptGamePassPurchase(player, gamePassId)
2. UserOwnsGamePassAsync
This function is used to check if given player owns the given gamepass id. Returns a bool value, Also normally used in LocalScript to check player's owned gamepass
Parameters: player, gamePassId
Example Code:
local MPS = game:GetService("MarketplaceService")
local gamePassId = 123
local player = game.Players.LocalPlayer
MPS:UserOwnsGamePassAsync(player, gamePassId)
3. PromptGamePassPurchaseFinished
This event is fired when a gamepass prompt closes. You can check if the player successfully bought it by checking if the purchase is success. Normally used in ServerScript to give something to the player after purchasing a gamepass
Parameters: player, passId, Success
Example Code:
local MPS = game:GetService("MarketplaceService")
MPS.PromptGamePassPurchasedFinished:Connect(function(player, passId, Success)
end)
Making The Gamepass
First, we want to prompt the gamepass after player clicks a gui button ( optional )
Local Script:
local MPS = game:GetService("MarketplaceService")
local button = script.Parent
local player = game.Players.LocalPlayer
local gamePassId = 123
button.MouseButton1Click:Connect(function()
MPS:PromptGamePassPurchase(player, gamePassId)
end)
Second, we want to check if the player already has the gamepass
Local Script:
local MPS = game:GetService("MarketplaceService")
local button = script.Parent
local player = game.Players.LocalPlayer
local gamePassId = 123
button.MouseButton1Click:Connect(function()
local hasGamePass = false
local succ, err = pcall(function()
hasGamePass = MPS:UserOwnsGamePassAsync(player, gamePassId)
end)
if hasGamePass then
warn("Already owned the gamepass")
else
MPS:PromptGamePassPurchase(player, gamePassId)
end
end)
Third, we want to give something to the player after they purchase the gamepass
Server Script:
local MPS = game:GetService("MarketplaceService")
local teamChangeGUI =
local gamePassId = 123
MPS.PromptGamePassPurchaseFinished:Connect(function(player, passId, Success)
if player and Success and passId == gamePassId then
local newGUI = teamChangeGUI:Clone()
newGUI = player.PlayerGui
end
end)
Fourth, you want to give player the gui after rejoining right? Then we need to use MarketPlaceService:UserOwnsGamePassAsync again
Server Script:
local MPS = game:GetService("MarketplaceService")
local gamePassId = 123
game.Players.PlayerAdded:Connect(function(player)
local hasPass
hasPass = MPS:UserOwnsGamePassAsync(player, gamePassId)
if hasPass then
end
end)
More Information:
MarketplaceService
1 comment
life would be easier if you just did "LocalPlayer.TeamColor" (assuming you found it with the players service)