So I’m making a game just like The Final Countdown, and I was told to use messaging service to communicate to all servers when a player purchases a dev product, which in turn will increase/decrease depending how much time they bought (+/-). I have the epox end time in a variable and when the code runs I :SetAsync to that time. Here is the code I have for the main loop:
while task.wait(1) do
local currentTime = os.time()
local timeLeft = timeStore:GetAsync("TIME") - currentTime -- I DONT KNOW WHAT TO DO HERE
local DaysLeft = math.floor((timeLeft / 60 / 60 / 24) % (365 + 0.2425))
local HoursLeft = math.floor((timeLeft / 60 / 60) % 24)
local MinutesLeft = math.floor((timeLeft / 60) % 60)
local SecondsLeft = math.floor(timeLeft % 60)
if currentTime >= startTime then
else
updateTime:FireAllClients(DaysLeft, HoursLeft, MinutesLeft, SecondsLeft, timeLeft)
end
end
So I just get the time for :GetAsync and subtract from the current time, then :FireAllClients() to update the UI
In my dev product receipt function is when I :IncrementAsync to the data store but for some reason it’s not working. Here is the code for the function:
local function ProcessReceiptYUH(receipt_info)
local player = Players:GetPlayerByUserId(receipt_info.PlayerId)
if player == nil then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local profile = GetPlayerProfileAsync(player)
if profile ~= nil then
GrantProduct(player, receipt_info.ProductId)
local name = MarketPlaceService:GetProductInfo(receipt_info.ProductId, Enum.InfoType.Product).Name
local str = name:gsub(" ", "")
local w
print(str)
for _, v in workspace:GetDescendants() do
if string.lower(v.Name) == string.lower(str) then
w = v
end
end
local amountToAdd = w:GetAttribute("time")
timeStore:IncrementAsync("TIME", amountToAdd)
msgService:PublishAsync("Y", timeStore:GetAsync("TIME"))
print("PUBLISHED MESSAGE")
return PurchaseIdCheckAsync(
profile,
receipt_info.PurchaseId,
function()
GrantProduct(player, receipt_info.ProductId)
end
)
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
MarketPlaceService.ProcessReceipt = ProcessReceiptYUH
Each model has an attribute, “time” which will be added to the datastore via :IncrementAsync, so that I can update the value, my issue is that when a player buys it, the value WILL update, but when I leave and join back it will just jump back to the same value, and I don’t know how to save the value. I thought :IncrementAsync will update the datastore even when a player joins back or am I wrong?
Help is appreciated!