how give perk for 24 hours using datastore, developer products?
i was reading the roblox blog about developer products and one line says, "You could sell tickets to exclusive and secret parts of your map for a day." so i know it's possible to sell a perk that lasts for as long as i want it to last. I'd like to sell one of my developer products and make it remain for 24 hours, but i don't know enough to make that happen.
right now i'm using the script i found in the wiki to sell the products.right now if the players reset or leave the server they will lose the perk. i just need someone to point me in the right direction to make it last for 24 hours.
01 | ` local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "Purchases" ) |
04 | MarketplaceService.ProcessReceipt = function (receiptInfo) |
06 | for i, player in ipairs (game.Players:GetChildren()) do |
07 | if player.userId = = receiptInfo.PlayerId then |
11 | local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId |
12 | ds:IncrementAsync(playerProductKey, 1 ) |
16 | return Enum.ProductPurchaseDecision.PurchaseGranted |
1 day later.... i've spent several hours trying to figure out a way to make this work but i am trying to do something beyond my scripting knowledge. if anyone can lend more help please do so. i will share the solution with the roblox community by posting it in the roblox forums. i think TheRobertDoges' idea with using utc time is a great part of the solution. i'm thinking i can record the time with purchaswe and then whenever players join the game it checks the datastore and if the purchase was made < 1000000 + (datastore time) then player would spawn with the perk. if purchase was mader > 1000000 + (datastore time) then nothing end. does that make any sense? the time format for utc is like 14digits and 1 day is like 1000000 or something.
would i do something like this?
01 | ` local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "Purchases" ) |
04 | local perkstore = game:GetService( "DataStoreService" ):GetDataStore( "Perks" ) |
10 | MarketplaceService.ProcessReceipt = function (receiptInfo) |
12 | for i, player in ipairs (game.Players:GetChildren()) do |
13 | if player.userId = = receiptInfo.PlayerId then |
17 | local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId |
18 | ds:IncrementAsync(playerProductKey, 1 ) |
20 | local playerperkId = player.userId |
21 | perkstore:SetAsync(playerperkId, buytime) |
25 | return Enum.ProductPurchaseDecision.PurchaseGranted |
and then another script
01 | local perkstore = game:GetService( "DataStoreService" ):GetDataStore( "Perks" ) |
04 | game.Players.PlayerAdded:connect( function (player) |
05 | player.CharacterAdded:connect( function (character) |
06 | while not player.Character do wait() end |
07 | local character = player.Character |
10 | local perktime = perkstore:GetAsync(player.userId) |
11 | if perktime ~ = nil then |
12 | if (perktime + 1000000 ) < nowtime then |