So i've made this gamepass to gives +50000 gold when the person who bought it rejoins/starts. But whenever they rejoin they still get 50000 gold, when they're only sopoused to get 50000 gold once. My Script
local GamePassID = 198893078 --game pass ID local gps = game:GetService("GamePassService") function playerJoined(newPlayer) if gps:PlayerHasPass(newPlayer,GamePassID) then newPlayer.leaderstats.Gold.Value = newPlayer.leaderstats.Gold.Value + 50000 end end game.Players.PlayerAdded:connect(playerJoined)
To do what you're trying to accomplish, we need to set up a DataStore, which we will fill with the users that have bought the GamePass.
First, lets define the DataStore key that we'll be using, and the gamepass required.
local ds = game:GetService("DataStoreService"):GetDataStore("IncreasedGold") local passId = 198893078
Now, lets have whenever a player joins.. we check if they have the gamepass. And if they have the gamepass, we check if they have data stored already. If they have data stored already it would mean that they've already been awarded the gold because if they don't have data, but have the gamepass.. then we're going to set up data(:
game.Players.PlayerAdded:connect(function(plr) wait(1) --Just to be safe local key = tostring(plr.userId).."_Bought" local data = ds:GetAsync(key) local stats = plr.leaderstats.Gold if data == nil then if game:GetService("GamePassService"):PlayerHasPass(plr,passId) then ds:SetAsync(key,true) --The actual value doesn't matter stats.Value = stats.Value + 50000 end end end)
So, lets put this whole script together. It should look like this:
local ds = game:GetService("DataStoreService"):GetDataStore("IncreasedGold") local passId = 198893078 game.Players.PlayerAdded:connect(function(plr) wait(1) --Just to be safe local key = tostring(plr.userId).."_Bought" local data = ds:GetAsync(key) local stats = plr.leaderstats.Gold if data == nil then if game:GetService("GamePassService"):PlayerHasPass(plr,passId) then ds:SetAsync(key,true) --The actual value doesn't matter stats.Value = stats.Value + 50000 end end end)
I also suggest maybe adding a checking with a CharacterAdded Event, so that the player doesn't have to rejoin upon buyig the gamepass.
If you have any other questions feel free to comment on my answer or PM me on the site(:
Well what you need to use it a Developer Product. You can use this script and just add the amount of cash you want it to add and also the ID of the Developer product. Dont forget you have to put this script in StarterPack.
local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") CASHID = 19382769 -- Put the Developer Product ID here MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId local numberBought = ds:IncrementAsync(playerProductKey, 1) for i,v in pairs (game.Players:GetChildren()) do if v.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == CASHID then lds = v:FindFirstChild("leaderstats") if lds ~= nil then cs = lds:FindFirstChild("Money") --Change to your leaderstat if cs ~= nil then cs.Value = cs.Value + 10 --Change to the amount you want this to add end end end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
Also here is the script to put in the GUI so that they can buy it:
local MarketplaceService = Game:GetService("MarketplaceService") local productId = 22137544 -- Dev Product ID script.Parent.MouseButton1Click:connect(function() MarketplaceService:PromptProductPurchase(script.Parent.Parent.Parent.Parent, productId) end)
Make sure that is a local script in the GUI. You can create a Dev Product by going to your game and hitting Configure this place then going to developer products and creating one. If this help please thumbs it up or accept answer!