Gifting Gamepass (aka Developer Product) System

Hello together,
I created a gifting gamepass system aka a system with which you buy a developer product and the player you want to gift it to will have the same options like he has the gamepass. Its working with developer products thats why i cant use MPC:UserOwnsGamepassAsync etc.

I want to improve the system how it basiclly works, because i got multiple times this error “the game server has reached the allowed limit of active subscriptions”, when i was using MessagingService to “interact” with a player another player wants to gift the gamepass to.
My goal is to set a value to true when someone gets gifted a gamepass through different servers.

I will explain how my system works right now:

  1. A remote event gets fired with the name of the player who will get the gamepass
  2. The Server checks if the player is in the server (a), if the player is offline (not in my game) (b) or if he is playing in another server (c)
    Note: Im checking if the player is online with DataStoreService. Im setting a value to true and save the data again when the player joins & set the value to false when he leaves
  • a: the server will check if the player already has the gamepass, when not the player who want to gift will get prompted with a developer product and if he buy it, the other player receive their gamepass (aka a value will be set to true when they “have” the “gamepass”). Everything works fine.

  • b: im checking if the data of the gamepass is set to false, if the value is false im prompting the player…(same as in a)…and at the end i will save the data. Everythings works fine.

  • c: A Message (MessagingService:PublishAsync()) will get published to all servers to request the data of the player (Im not using datastore here, because the data gets updated every 300 seconds and the player could buy the gamepass after the data got updated, so you could gift someone a gamepass they already have). Another published message will “return” (its not really “returning”, its just publishing another message to bring the infos back to the server where the player who want to gift is in) the requested infos (if the player already owns the gamepass aka if the value for the gamepass is already true). If the value for the gamepass is false, the player who want to gift will get prompted. When they buy the developer product another message will get published to set the value of the player to true.

Scenario c is using MessagingService:PublishAsync() and MessagingService:SubscribeAsync() each 3 times.

At the end i have to say my english is horrible and this is my 1st devforum post so if you have any questions: Feel free to ask

Thank you for reading!

3 Likes

I think you are trying to gift gamepasses here if I’m not mistaken, and you shouldn’t do this, you should not be able to gift gamepasses, because the recipient of the gift/gamepass, can still buy it in the store page.

Instead make a datastore for gamepasses owned, and make the “gamepasses” devproducts, put them in an in-game store, where a player can easily see which ones they own, and which ones they don’t, similar to the store page on the website. When a player buys the product, check if they own it already, if they do, they can’t buy it again, if they don’t, they buy it, and set the datastore table to reflect that. If a player asks to gift the item, check if the recipient owns it, if not, then the player who is gifting it pays, and the datastore with the key of the recipient’s id will get updated

Datastore formatting

I personally would format the “gamepass” datastores, by saving with the player’s UserId, then when they buy a devproduct/“gamepass”, the datastore would append the productId to the array (not dictionary), then using table.find we could check if a player owns the “gamepass”

When I use “gamepass” with quotes I am referring to the devproducts taking the place of gamepasses

3 Likes

This is a good idea, but

  1. the Text in the shop which says like “buy for …robux” or “owned” wouldnt update until you try to buy it

  2. there wouldnt be a message to the player so he knows another person gifted him a gamepass

Um, can you elaborate on 1., and for 2., we can just add more data on the datastore, like saving "~ProductId~,Gifted" or "~ProductId~", then using string.split(str, ",") we can get the productId = result[1] and if it was gifted, messageGifted = if result[2] then result[2] == "Gifted" else false, then we can set the dataStore to be “~Productd~,Gift”, which shows us the gift message already went through. wasGifted = if result[2] then result[2] == "Gift" else false

local str = -- get from datastore
local result = string.split(str, ",") -- the infomation

local productId = result[1] -- the productId

local messageGifted = if result[2] then result[2] == "Gifted" else false -- if we need to tell the player they got a gift

local wasGifted =  if result[2] then result[2] == "Gift" else false -- if the product/"gamepass" was gifted, and the player had seen the message of getting the gift

After writing this I realized you could also save a table with the information, with a better result, if you want me to do that I can, but I believe the basic idea has been presented.

that was not my question…when changing data in a datastore i cannot update the text when the datastore changed and i cant really message the player when he got the gamepass

Simply use the method of checking of the player is online, if they are in a different server, send use messaging service, if not the server can handle it, if offline, then when the player loads in next session, the datastore also loads, with the data.

I left this part out in the earlier message because you already had a system in place that did that and assumed you would just do that.

Also, can you please explain what you mean by the text not updating?

local hasProduct = if result[3] then result[3] == “True” else false – if the player has the product/“gamepass”

if hasProduct then – do something, when the player has already the product/“gamepass”
return
end

if messageGifted then – show the player the message that they got a gift
– show message
– set the value of messageGifted to false, so it doesnt get shown again
return
end

if wasGifted then – if the player has already been gifted a product/“gamepass”
– do something
return
end

– buy the developer product

MessagingService:PublishAsync()
MessagingService:PublishAsync()
MessagingService:PublishAsync()

MessagingService:SubscribeAsync()
MessagingService:SubscribeAsync()
MessagingService:SubscribeAsync()

If you have a gamepass system in mind, have you considered using the MPC API?
It allows you to check if a player has bought a gamepass, and you can use the Purchased event to keep track of who bought what.

This doesn’t solve my problem I don’t wanna use messaging service:publishasync that much and the developer product is not available as a gamepass, because I’m resetting the value regularly

So like your idea is to make everything from the server the gifter is in and send 1 message to the other server to tell that a player got gifted the gamepass?

I’m a little confused how you worded it, so I’ll bring up the scenarios.

  1. Recipient is in the server - Server can call the function that manages the ui saying the player got a gift, if player successfully gets the message save with {~ImageId~, “Gift”} or “~ImageId~,Gift” (depending on how you want to save your data), if the player doesn’t get the message, or gets the message then leaves 1 - 2 seconds after, save it as {~ImageId~, “Gifted”} or “~ImageId~,Gifted”.

  2. Recipient is in another server - Save either {~ImageId~, “Gifted”} or “~ImageId~,Gifted” (Depending on how you want to save your data), then using messaging service with the UserId of the recipient, all servers will check if they are in that server, once found, you load the “gamepass” dataStore, then send the message, with the same method as in scenario 1. with the same saving method.

  3. Recipient is offline - Save either {~ImageId~, “Gifted”} or “~ImageId~,Gifted” (Depending on how you want to save your data), and when the player logs on, just check if anything is in their datastore, and has “Gifted” instead of “Gift” or nil.

Again, it is very important to load the “gamepass” DataStore, because the player needs access to their dataStores, which are in the form of DevPoducts to give the functionality of gifting.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.