Why is this subscrition system code not working

I’m trying to do a subscription system using os.date, but it’s not working fine and I really can’t see why it isn’t working.

game.ReplicatedStorage.Comminications.Place.OnServerEvent:Connect(function(plr,place)
	date = os.date("*t", os.time())
	local DataName = DataService:GetDataStore(place)
	if place == "Admin" then
		out("Waiting for Teleport Service...")
		local TeleportService = game:GetService("TeleportService")
		local teleportData = {
			DataStore = place
		}
		TeleportService:Teleport(7122358798, plr, teleportData)
	else
		local s, e = pcall(function()
			local expire = DataName:GetAsync("Subscription")
			print("D: "..date.month.." | E:"..expire.month)
			if date.year >= expire.year and date.month >= expire.month and date.day >= expire.day then --and date.hour >= expire.hour and date.min >= expire.min and date.sec >= expire.sec then
				out("Waiting for Teleport Service...")
				local TeleportService = game:GetService("TeleportService")
				local teleportData = {
					DataStore = place
				}
				TeleportService:Teleport(7122358798, plr, teleportData)
			else
				out("ERROR#002 > Code Expired!")		
			end
		end)
		if e then
			out("ERROR#001 > Invalid code!")
		end
	end
end)

Any idea on what’s wrong with my code?

What is “out” supposed to do exactly?

It’s a function that displays a visual message on player’s Gui

Also what exactly isn’t working?
Is it not teleporting you?
Do you get all the messages that it sends properly?
Any error messages?

It always says that the code is expired (and it’s not expired)


image

From what I see the error is somewhere in this if statement although I am not sure what it is due to lack of information.

Could you send a before the if statement: print(date.year) print(expire.year) print(date.month) print(expire.month) print(date.day) print(expire.day)
And send me the output.

image

game.ReplicatedStorage.Comminications.Place.OnServerEvent:Connect(function(plr,place)
	date = os.date("*t", os.time())
	local DataName = DataService:GetDataStore(place)
	if place == "Admin" then
		out("Waiting for Teleport Service...")
		local TeleportService = game:GetService("TeleportService")
		local teleportData = {
			DataStore = place
		}
		TeleportService:Teleport(7122358798, plr, teleportData)
	else
		local s, e = pcall(function()
			local expire = DataName:GetAsync("Subscription")
			print("D: "..date.month.." | E:"..expire.month)
			print(date.year,expire.year,date.month,expire.month,date.day,expire.day)
			if date.year >= expire.year and date.month >= expire.month and date.day >= expire.day then
				out("Waiting for Teleport Service...")
				local TeleportService = game:GetService("TeleportService")
				local teleportData = {
					DataStore = place
				}
				TeleportService:Teleport(7122358798, plr, teleportData)
			else
				out("ERROR#002 > Code Expired!")		
			end
		end)
		if e then
			out("ERROR#001 > Invalid code!")
		end
	end
end)

Nevermind, hold on. Let me take a look.

Oops, that’s a really stupid error… Although now it says that all the codes are expired, expired and active ones. I checked with >= and it says expired codes are active and active ones are expired, but changing to <= just says that everything is expired

That’s because 8 < 12 but 28 > 20

Well, reading what I said, I just realized that just moving the code that teleports and the code that says the code is expired works fine

Nevermind, you are right lol

One thing I can think of is make the script check if the year is <= 2021 IF IT IS then check if the month is <= 12 IF IT IS then check if day is <= 20

Basically if the month is smaller than 12 the script won’t need to check the day since it knows it’s not expired.

I’ll try with that, I’ll let you know if it works

Thanks, it worked!

game.ReplicatedStorage.Comminications.Place.OnServerEvent:Connect(function(plr,place)
	date = os.date("*t", os.time())
	local DataName = DataService:GetDataStore(place)
	if place == "Admin" then
		out("Waiting for Teleport Service...")
		local TeleportService = game:GetService("TeleportService")
		local teleportData = {
			DataStore = place
		}
		TeleportService:Teleport(7122358798, plr, teleportData)
	else  
		local s, e = pcall(function()
			local expire = DataName:GetAsync("Subscription")
			if expire.year <= date.year then
				if expire.month <= date.month then
					if expire.day <= date.day then
						out("ERROR#002 > Code Expired!")
						return 
					end
				end
			end
			out("Waiting for Teleport Service...")
			local TeleportService = game:GetService("TeleportService")
			local teleportData = {
				DataStore = place
			}
			TeleportService:Teleport(7122358798, plr, teleportData)
		end)
		if e then
			out("ERROR#001 > Invalid code!")
		end
	end
end)