So, I'm trying to make a Membership type of DevProduct. This means they can buy a membership, as a DevProduct (or something else), which will last for a certain amount of time. I've seen this on many games such as The Mad Murderer 2, yet I have no idea where to start from.
I've thought of many things. The first thing I thought was to make an IntValue with a certain amount of seconds always counting down. That IntValue then has a DataStore script saving which value it's at. The problem is, it would only countdown when the player is in the game, which is something I do not want.
So please, where do I start from?
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.
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 -- membership time in seconds (because remember timestamps are in seconds) processReceipt = function(info) -- the callback. pcall(function() -- remember to check for web service errors from Roblox, a -- nd maybe do more error handling than I do here. expirationtimestamp = mydatastore:GetAsync(info.PlayerId) -- old timestamp currenttime = os.time() -- we get a new timestamp if expirationtimestamp > currenttime then mydatastore:SetAsync(info.PlayerId, expirationtimestamp + constant) -- we add to the expiration time. 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 -- Assuming you know who the player is. expiration = mydatastore:GetAsync(player.UserId) currenttime = os.time() if currenttime < expiration then -- they are still a member end
HERE IS THE GOOD LINK AND DON'T CLICK THE DOWNWOTE BEACAUSE I WILL HAVE LOW REPUTATION !!!
EDIT : WHO THE HECK CLICKED THE DOWNVOTE ?! I AM SO F*****G T R I G G E R E D !