Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how give perk for 24 hours using datastore, developer products?

Asked by 10 years ago

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")
02local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
03 
04MarketplaceService.ProcessReceipt = function(receiptInfo)
05 
06    for i, player in ipairs(game.Players:GetChildren()) do
07        if player.userId == receiptInfo.PlayerId then
08blahblahblah.....
09end end
10 
11    local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId
12    ds:IncrementAsync(playerProductKey, 1)
13 
14 
15    -- tell ROBLOX that we have successfully handled the transaction
16    return Enum.ProductPurchaseDecision.PurchaseGranted    
17end`

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")
02local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
03 
04local perkstore = game:GetService("DataStoreService"):GetDataStore("Perks")
05local buytime = Game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true)
06 
07 
08 
09 
10MarketplaceService.ProcessReceipt = function(receiptInfo)
11 
12    for i, player in ipairs(game.Players:GetChildren()) do
13        if player.userId == receiptInfo.PlayerId then
14blahblahblah.....
15end end
View all 26 lines...

and then another script

01local perkstore = game:GetService("DataStoreService"):GetDataStore("Perks")
02local nowtime = Game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true)
03 
04game.Players.PlayerAdded:connect(function(player)
05player.CharacterAdded:connect(function(character)
06    while not player.Character do wait() end
07    local character = player.Character
08 
09 
10local perktime = perkstore:GetAsync(player.userId)
11if perktime  ~= nil then
12   if  (perktime + 1000000) < nowtime then                   
13     giveperk
14else
15  end end
16 
17   end)
18end)

1 answer

Log in to vote
1
Answered by 10 years ago

Sending a GET request to this link with the HttpService should give you the time:

1Game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true) -- This would get the current utc time.

Obviously you wouldn't want to be spamming this (ROBLOX will eventually stop you from clogging up the servers), so you will probably only want to do a check every few minutes.

When the person buys your product, record the time in the DataStore.

1
wow ty. i'm sure i will have to use this as part of the script. johnnygadget 50 — 10y
0
Np Monsieur_Robert 338 — 10y
Ad

Answer this question