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

How to change team with gamepass?

Asked by 5 years ago

I've been working on a game for over a week now nonstop but I keep running into problems with my scripts and ui's. When I make a script for a gamepass so when you click it changes your team but nothing works.

1
Include the code you are having a problem with. Explain the errors you're getting and anything else helpful for us to understand. xPolarium 1388 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Okay i'll try and guide you, but i'm going to use a Developer Product as that's what im farmiliar with

So inside a button on the players UI, have a button linking to a developer product (Local script)

local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
    MarketplaceService:PromptProductPurchase(player, insert developer product id here)
end)

Then, in a script in server script service

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")

local PreviousPurchases = DataStoreService:GetDataStore("Receipts")

local developer_product_id = 12342134214(whatever the product id actually is)

MarketplaceService.ProcessReceipt = function(receipt)

--This bit checks if they have already purchased it
    local ID = receipt.PlayerId.."-"..receipt.PurchaseId

    local success = nil

    pcall(function()
        success = PreviousPurchases:GetAsync(ID)
    end)

    if success then -- Has it already been bought ?
        -- Purchase has already been done
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    local player = game.Players:GetPlayerByUserId(receipt.PlayerId)

    if not player then
        -- Left, disconnected
        return Enum.ProductPurchaseDecision.NotProcessedYet -- We're going to give their rewards next time they join / next time fired
        else

        if receipt.ProductId == developer_product_id
            --Insert script here to change teams
        end

        pcall(function()
            PreviousPurchases:SetAsync(ID,true)
        end)

        return Enum.ProductPurchaseDecision.PurchaseGranted

    end
end

This is a modified script from an AlvinBlox tutorial, so I can't take full credit :P

Ad
Log in to vote
0
Answered by 3 years ago

use/try this:

local gamepassID = ******

script.Parent.MouseButton1Click:connect(function (playerWhoClicked)
    local player = game.Players.LocalPlayer
    local gps = game:GetService("GamePassService")
    local playerHasPass = gps:PlayerHasPass(player, gamepassID)

    if playerHasPass then
          player.Team.Name = "HATO"
    else
        gps:PromptPurchase(player, gamepassID)
    end
end)

i think its work

Answer this question