Hi, so I’m trying to create a birthday reward system where, if the system determines that you’ve had a birthday since your last time playing, it’ll give you a reward.

My issue is I’m trying to figure out the logic to do this. I figured this would be the easiest way:

local is_birthday = (player.AccountAge % 365 == 0)

But, I realized that’d only work if they play it on their birthday…and I’m not into the idea of saving their AccountAge when they first join, then determine if it’s been 365 days since that point to give them a reward; that isn’t accurate either.

I can clarify more if needed, any help appreciated. Thanks!

You would have to store the last account age since they last played as there is no way to know when they last played that I am aware of. With this, you could save their current calculated age (age % 365) when they leave or while they play. When loading, check the last account age that was saved and compare it to the current calculation. This comparison can check to see if it is less than the saved calculated age. The reason this works is that if they join on the 364th day and the next day they join it would be the 365th day. 365 % 365 would be 0 which is less than 364. If they join 2 days later it would be 1 ((364 + 2) % 365 = 1) which is less than 364. Now lets say they join again on the 365th day this would be 0, but since 0 was saved it would not reward again. This also assumes that if 2 birthdays pass they only get rewarded once. There may be a more simple solution to this.

Since AccountAge represents the number of days the user has existed, maybe you could multiply that by 86400 (seconds in a day), then subtract it from os.time() to get an accurate approximation of the player’s join date.

If a player joins on a date after their birthday the game could give the award then increment some kind of variable to make sure they don’t get the award again until next year.

Actually I think I’ve already answered a question like this you already had: