Skip to main content

In game purchases

Important

Polytoria sadly does not allow you to prompt any type of purchases to a user.

You can still check for purchases using the OwnsItem method under the Player class.

warning

The OwnsItem method will cache the result for 5 minutes. If a player purchases your gamepass after you have checked once, they will need to wait 5 minutes before you can verify the purchase.

Create a gamepass

You need to first create your gamepass from https://polytoria.com/create

While creating you need to pick a name, and description for your gamepass. After created you can publish it and set the price.

After this you can copy the ID of the gamepass. Save this ID as we will use it to check for the purchase.

Check a purchase

For a gamepass, we will be checking the purchase once a player joins. This is ideal for our setup since we cannot check if a player has purchased the product in game.

Create a ScriptInstance and place it under ScriptService

Register events

Firstly we need to register the PlayerAdded event to check when a player joins our game.

local Players = game["Players"] -- Get the Players service

Players.PlayerAdded

Connect the event

We then need to connect the event to a function so our script can execute it.

local Players = game["Players"]

Players.PlayerAdded:Connect(function(player) -- The event gives us the player parameter
end)

Check for gamepass

Now that the event is connected to a function, we use the OwnsItem method to check if the player owns our gamepass.

Let's also create a variable for our gamepass ID so we can change it easily if needed.

local Players = game["Players"]
local gamepassId = 0000 -- Add the ID of the gamepass that you have created earlier on

Players.PlayerAdded:Connect(function(player)
player:OwnsItem(gamepassId, function(error, owns) -- The OwnsItem method will return us an error, and a boolean of whether the player owns the item or not
if error then
print("An error occurred!")
else
if owns then
print("Player owns the gamepass") -- Here you can execute other code such as giving them a tool!
else
print("Player does not own the gamepass") -- The player does not own the gamepass!
end
end
end)
end)