Adding additional vip time to players


-- Developer product script for 7 days vip
productFunctions[123456] = function(receipt, player)
  local leaderstats = player:WaitForChild("leaderstats")
  local vipTime = leaderstats:WaitForChild("VipTime")
  local vipExpireTime = leaderstats:WaitForChild("VipExpireTime")
  local sevenDays = 604800  

  -- Set vipTime to today and set vipExpireTime to seven days from now.
  if vipExpireTime.Value > 0 then
    vipTime.Value = os.time()
    vipExpireTime.Value = sevenDays
    print("Assigning player VIP")
  else
    -- Calculate remaining time and add to time for seven days and set vipTime to today.
    local currentTime = os.time()
    local remainingTime = currentTime - vipTime.Value
    vipExpireTime.Value = remainingTime + sevenDays
    vipTime.Value = os.time()
    print("Assigning additional VIP time!")
  end
  return true
end

Are there any issues from the way I’m doing it? So if someone were to buy vip on Monday and purchase it on Thursday, they would have 3 days left (302400) and it would add 302400+ 604800 = 907,200, which would be 10 days total.

Any help is appreciated. Thank you!

Instead of saving the amount of time left just save when it will expire

Here

productFunctions[123456] = function(receipt, player)
  local leaderstats = player:WaitForChild("leaderstats")
  local vipExpireTime = leaderstats:WaitForChild("VipExpireTime")
  local sevenDays = 604800  

  -- Set vipTime to today and set vipExpireTime to seven days from now.
  if vipExpireTime.Value > 0 then
    vipExpireTime.Value = os.time + sevenDays
    print("Assigning player VIP")
  else
    -- Calculate remaining time and add to time for seven days and set vipTime to today.
    local currentTime = os.time()
    local remainingTime = currentTime - vipTime.Value
    vipExpireTime.Value = os.time + sevenDays
    print("Assigning additional VIP time!")
  end
  return true
end

By doing this you could simply do

local leaderstats = player:WaitForChild("leaderstats")
local vipExpireTime = leaderstats:WaitForChild("VipExpireTime")

print(os.time - vipExpireTime <= 0) -- Prints true if vip has expired