Feedback on my Vip subscription system

So, I have made a VIP Subscription system. And this is my first VIP system.
Please, Give me your feedback.

Code:

game.Players.PlayerAdded:Connect(function(player)
	local subscriptionStore = DataStore2("subscription", player)

	local subscribed = Instance.new("BoolValue")
	subscribed.Name = "Subscribed"
	subscribed.Parent = player
	
	local subscriptionInfo = subscriptionStore:Get(defaultInfo)

	if subscriptionInfo then
		if subscriptionInfo.Subscribed then
			if os.time() < subscriptionInfo.Expiration then
				subscribed.Value = true
			else
				subscriptionInfo.Subscribed = false
				subscriptionInfo.Expiration = nil
				subscriptionStore:Set(subscriptionInfo)
				subscribed.Value = false
			end
		else
			subscribed.Value = false
		end
	end

	coroutine.wrap(function()
		while true do
			local subscriptionInfo = subscriptionStore:Get(defaultInfo)

			if subscriptionInfo then
				if subscriptionInfo.Subscribed then
					if os.time() < subscriptionInfo.Expiration then
						subscribed.Value = true
					else
						subscriptionInfo.Subscribed = false
						subscriptionInfo.Expiration = nil
						subscriptionStore:Set(subscriptionInfo)
						subscribed.Value = false
					end
				else
					subscribed.Value = false
				end
			end
			wait(5)
		end
	end)()
end)

Default value:

local defaultValue = {
Subscription = false,
Expiration = nil
}

this is using DataStore2 btw.

2 Likes

Subscription information should be saved with the rest of your player data if you have any and you can store the timer value somewhere in a cache on the server instead of running your same getter function every 5 seconds in a coroutine; would be much easier to do in-session subscription expiry that way.

Ok, I’ll try to do that! Thanks for the feedback!