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)

1local MarketplaceService = game:GetService("MarketplaceService")
2local player = game.Players.LocalPlayer
3 
4script.Parent.Activated:Connect(function()
5    MarketplaceService:PromptProductPurchase(player, insert developer product id here)
6end)

Then, in a script in server script service

01local MarketplaceService = game:GetService("MarketplaceService")
02local DataStoreService = game:GetService("DataStoreService")
03 
04local PreviousPurchases = DataStoreService:GetDataStore("Receipts")
05 
06local developer_product_id = 12342134214(whatever the product id actually is)
07 
08MarketplaceService.ProcessReceipt = function(receipt)
09 
10--This bit checks if they have already purchased it
11    local ID = receipt.PlayerId.."-"..receipt.PurchaseId
12 
13    local success = nil
14 
15    pcall(function()
View all 42 lines...

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 4 years ago

use/try this:

01local gamepassID = ******
02 
03script.Parent.MouseButton1Click:connect(function (playerWhoClicked)
04    local player = game.Players.LocalPlayer
05    local gps = game:GetService("GamePassService")
06    local playerHasPass = gps:PlayerHasPass(player, gamepassID)
07 
08    if playerHasPass then
09          player.Team.Name = "HATO"
10    else
11        gps:PromptPurchase(player, gamepassID)
12    end
13end)

i think its work

Answer this question