✓ Accepted answer
This is a good question. The few constraints we would need to consider are that people can buy the membership repeatedly while still having a membership. We would not want to cut their time short, so we need some way of adding to when it will expire.
I would implement this with the following tools.
timestamps from os.time a timestamp is a way of expressing what the date and time is at a particular point. For example, when I am writing this question os.time returns 1513446506. (This means that many seconds have passed since the 1970 January 1st Epoch that you can read about here) By getting the difference with the next os.time that we call, we can track how many seconds have passed.
the process receipt callback from the MarketPlace Service (example is here)
data stores to track the timestamps from two bullets above.
The idea is that you track when membership will expire in terms of timestamps. You renew this expiration time in a data store when purchases are made.
I would implement it with something like the following and I assume that you can fill in the rest.
constant = 86400
processReceipt = function(info)
pcall(function()
expirationtimestamp = mydatastore:GetAsync(info.PlayerId)
currenttime = os.time()
if expirationtimestamp > currenttime then
mydatastore:SetAsync(info.PlayerId, expirationtimestamp + constant)
else
mydatastore:SetAsync(info.PlayerId, currenttime + constant)
end
end)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
And then when a player logs in to make sure that they have membership you would do.
local player
expiration = mydatastore:GetAsync(player.UserId)
currenttime = os.time()
if currenttime < expiration then
end
2 comments
Timestamps are a way of tracking time. We store timestamps so that we can compare them using basic comparisons such as equal to (same time), less than (something occured before), or greater than (something occured later).
As long as you understand the above, you can work with experimenting with timestamps to understand how to implement your membership idea.