Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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.

`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

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.

2 comments

1

wow ty. i'm sure i will have to use this as part of the script.

0

Np

This discussion is preserved as it was. New answers, comments, and votes are closed.