Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a gamepass exclusive team change button?

Asked by 3 years ago

So basically i made a button that allows me to change team, but im trying to make it turn into a gamepass exclusive and if you dont have the gamepass the purchase prompt appears. heres the code i have, i need to know how to make it a gamepass only:

function Click(mouse) 
    script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Light blue") 
end 

script.Parent.MouseButton1Click:connect(Click) 

Keep in mind Its within a text button.

0
life would be easier if you just did "LocalPlayer.TeamColor" (assuming you found it with the players service) speedyfox66 237 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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 -- your gamepass id here

local player = game.Players.LocalPlayer

MPS:PromptGamePassPurchase(player, gamePassId) -- player and gamepass id

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 -- your gamepass id here

local player = game.Players.LocalPlayer

MPS:UserOwnsGamePassAsync(player, gamePassId) -- returns true or false

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 -- your gui button
local player = game.Players.LocalPlayer

local gamePassId = 123 -- your gamePassId

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 -- your gui button
local player = game.Players.LocalPlayer

local gamePassId = 123 -- your gamePassId

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")
        -- you can make a text that shows if the player owns 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 = -- your team change gui/button

local gamePassId = 123 -- your gamePassId

MPS.PromptGamePassPurchaseFinished:Connect(function(player, passId, Success)
    if player and Success and passId == gamePassId then
        -- if the player is still in game, success and the meant gamepass
        local newGUI = teamChangeGUI:Clone()
        newGUI = player.PlayerGui -- gives player the gui
    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 -- your gamePassId

game.Players.PlayerAdded:Connect(function(player)
    local hasPass

    hasPass = MPS:UserOwnsGamePassAsync(player, gamePassId)
    if hasPass then -- if player has the gamepass
        -- clone your gui to their playergui 
    end
end)

More Information: MarketplaceService

0
This really helps me A LOT. Thank you so much! Matrixmaximus867 11 — 3y
Ad

Answer this question