#Concern

1 messages · Page 1 of 1 (latest)

merry coyote
#
MarketplaceService.ProcessReceipt = function(receiptInfo)
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
    if receiptInfo.ProductId == gamepassId then
        local now = os.time()
        local currentExpire = activeBoosts[player.UserId] or now
        local newExpire = currentExpire > now and (currentExpire + boostDuration) or (now + boostDuration)
        activeBoosts[player.UserId] = newExpire
        applySpeed(player, true)
        UpdateBoostTimer:FireClient(player, newExpire)
        print("Remote Event fired!")
        
        task.spawn(function()
            while os.time() < newExpire do
                task.wait(1)
            end
            if activeBoosts[player.UserId] == newExpire then
                applySpeed(player, false)
                activeBoosts[player.UserId] = nil
            end
        end)
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    return Enum.ProductPurchaseDecision.NotProcessedYet
end

Players.PlayerAdded:Connect(function(player)
    local success, data = pcall(function() 
        return speedStore:GetAsync(player.UserId) 
    end)

    if success and data and os.time() < data then
        activeBoosts[player.UserId] = data
        applySpeed(player, true)
        print("Data loaded!")
        UpdateBoostTimer:FireClient(player, data)
        print("Remote Event fired!")
        task.spawn(function()
            while os.time() < data do
                task.wait(1)
            end
            if activeBoosts[player.UserId] == data then
                applySpeed(player, false)
                activeBoosts[player.UserId] = nil
            end
        end)
    end
end)

Players.PlayerRemoving:Connect(function(player)
    pcall(function()
        speedStore:SetAsync(player.UserId, activeBoosts[player.UserId])
    end)
end)
#

Hey I have a question

#

Since os.time() returns the seconds from unix timestamp, wouldnt the script cause issues while the server is offline?

#

like the if condition will become true after probably after like 50 seconds joining the server

merry coyote
#

yep i was right

#

can anyone help me find a better solution