Scripting Server Renewal

I’m pretty sure my math is way off, I’m confused why this isnt working properly.

When a server is created its given 30 days (1 month before it expires), In this example I set it to 1 for its timestamp.

It seems to add the time correctly of 7 days (1 week), however when I attempt to renew the server again without modifying its timestamp to 1, the math gets completely messed up.

GetTimestampFromString

local module = {}
function module:get(str)
	local now = os.time()

	if string.sub(str, -3) == "sec" then
		return now + tonumber(string.sub(str,0,-4))
	end
	if string.sub(str, -3) == "min" then
		return now + (tonumber(string.sub(str,0,-4)) * 60)
	end
	if string.sub(str, -3) == "hrs" then
		return now + (tonumber(string.sub(str,0,-4)) * 60 * 60)
	end
	if string.sub(str, -1) == "d" then
		return now + (tonumber(string.sub(str,0,-2)) * 60 * 60 * 24)
	end
	if string.sub(str, -1) == "w" then
		return now + (tonumber(string.sub(str,0,-2)) * 60 * 60 * 24 * 7)
	end
	if string.sub(str, -1) == "y" then
		return now + (tonumber(string.sub(str,0,-2)) * 60 * 60 * 24 * 7 * 52)
	end
	if string.sub(str, -1) == "p" then
		local str = "12"
		return "perm", now + (tonumber(string.sub(str,0,-2)) * 60 * 60 * 24 * 7 * 52)
	end
end
return module

secondsUntilDate

function secondsUntilDate(year, month, day, hour, minutes, seconds)
	local date = {year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
	local currentTime = os.date("*t")
	return os.time(date)-os.time(currentTime)
end

Renewal

function RenewServer(player, days)
	local PlaceId = player.PlayerGui.BloxM.Framework.Renew.Select.Value
	local ServersListing = DataStoreService:GetDataStore("BloxM_ServerListing")
	local Servers = ServersListing:GetAsync("servers_beta_3")

	for i,Details in pairs(Servers) do
		local OtherMath = os.date("*t", Details.Expiration)
		local Until = secondsUntilDate(OtherMath.year, OtherMath.month, OtherMath.day, OtherMath.hour, OtherMath.min, OtherMath.sec)
		local NewExpire = GetTimestampFromString:get(days) + GetTimestampFromString:get(Until.."sec")
		
		if Details.ServerOwner == player.UserId and Details.PlaceId == PlaceId then
			NotificationService:send(player, "Server Admin", "Additional Time added. If it failed to update please screenshot this message and send this to vq9o. \n \n RAMPAGE Data Packet: \n \n Server Name:	".. Details.ServerName .."\n RageId: ".. Details.PlaceId .."\n Owner: ".. Details.ServerOwner .. "\n Expires: ".. GetTimeFromString:get(NewExpire - os.time()))
			Details.Expiration = NewExpire
		end
	end

	wait(.2)
	ServersListing:SetAsync("servers_beta_3", Servers) 
end

Renewing for first time:

Renewing for second time:
image

You probably need to reset the text and regenerate the module script. That would be the only fix I have for you!

What do you mean, can you explain a little more?

When it shows the message for them to renew it, you should add to the module to change the text, then make a copy and place it in the same storage the module is in, then destroy the current module. That would probably be the only fix.

I don’t think that the issue, my issue is its trying to add new expiry time & current expire time together.