Creating products that last X amount of time

So I am sure other games have this but the main one I am thinking of is Loomian Legacy. When you use a Loomiboost, you can increase your chances to get different things for X amount of minutes. I am trying to achieve this but with a promo code. Everything with the promo codes is fine I am just stuck on how I should set up a counter going down from, let’s say, 20 minutes. I am storing the Buffs and the time left on the buffs in my datatable which looks a little something like this

	[Player] = {	
		[TypeOfBuff] = TimeLeftOnBuff
	}

When the player joins I load their data, check to see if they have any buffs and then put it into a session table. From there I am a little confused about where to go. I don’t even have an efficient system to count the time down yet. I planned to use coroutines and a while loop checking to see if the [Player][TypeOfBuff] > 0 but I can’t use this for multiple buffs at a time. I would also like to display the time, an easy way is to just insert a new IntValue into the Frame displaying the time and have a remoteEvent firing every time the time changes. Though there could be other ways. I’m sure this question has been asked before but I can’t find the right words to find an accurate explanation on where to start with this.

Instead of storing the time left, store when the buff will expire. Check if the buff is active when the player receives XP or anything like that.

3 Likes

Store the time that the buff will expire, then test if the buff is active. I would use os.time(). To get when the buff will expire, just add x seconds (os.time is in seconds) to os.time and then your buff will expire at that.

Alternatively, if you wanted the buff to only count for when the user is playing, you could store how much time is left on the buff and have a loop continuously subtract 1 until it gets to 0. If you do this, then you can just add an if statement at the end and then remove the buff from the table when its 0.

3 Likes