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 9 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.

`local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")

MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
blahblahblah.....
end end

    local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)


    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end`

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?

`local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")

local perkstore = game:GetService("DataStoreService"):GetDataStore("Perks")
local buytime = Game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true)




MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
blahblahblah.....
end end

    local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)

    local playerperkId = player.userId
       perkstore:SetAsync(playerperkId, buytime)


    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end`

and then another script

local perkstore = game:GetService("DataStoreService"):GetDataStore("Perks")
local nowtime = Game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true)

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
    while not player.Character do wait() end
    local character = player.Character


local perktime = perkstore:GetAsync(player.userId)
if perktime  ~= nil then
   if  (perktime + 1000000) < nowtime then                    
     giveperk
else
  end end

   end)
end)

1 answer

Log in to vote
1
Answered by 9 years ago

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

Game: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 — 9y
0
Np Monsieur_Robert 338 — 9y
Ad

Answer this question