Hello developers!
I’ve been trying to make a gamepass rewards script that gives the player 1K gold when they buy it, but everytime they join the game they get the gold again. How would i prevent this to only award the gold once?
Script:
game.Players.PlayerAdded:Connect(function(player)
if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId, 39670714) then
player:WaitForChild("UnlockedTowers"):WaitForChild("Bomber").Value = true
player:WaitForChild("Stats").PlayerGold.Value += 1000
end
end)
Any help is appreciated!
You don’t run the logic every time they rejoined the same game. You should only just prompt them the gamepass purchase only once, and then when it’s done, you handle the MarketplaceService.ProcessReceipt
call back to handle the logic of rewarding them. You can read more about them here.
Add a boolean stat. An example name could be ReceivedGoldFromPass.
Check the boolean when they join the game.
This will require saved player data/leaderboards and a method of doing this is with DataStores.
That’s just too complicated, my method is more suitable than yours.
1 Like
I thought ProcessReceipt was only for developer products, thank you!
It works for any purchases made in game.
The issue at hand is Gamepass, not Dev Products. The purchase is made outside of the game and needs to be verified once they join. If they purchase the Gamepass from the website, the user would not recieve rewards from a purchase processing script since the purchase doesn’t even take place in the game.
Good point, you should’ve clarified better. In that case that’s where data stores should be used, however in this context I would prefer rhe OP to use developer products over gamepasses as they can be purchased again and again.
My suggested solution was quite clear and concise. OP’s issue and description was also very direct about Gamepass rewards.
You discredited my solution in favor of yours. You shouldn’t be so judgemental, the forums are meant to help everyone. Multiple ways of solving an issue should always be welcome, whether they agree with your preferred methods or not.
1 Like
Again, you should’ve clarified better before you judge my comment. You could’ve explained the part where players could purchase the gamepass outside the game in your first comment but whatever. 