Question about making a Daily Rewards System

Hello,

So I’m wondering about handling the task of making a Daily Rewards System, I already understand the usage of os.time() or os.date() to make this system, but I was wondering on how to check the dates and if the Time the Player has joined is within the next consecutive day, but if they miss that day, the Data will reset? I’m not asking for a script, I’m merely asking for an explanation like what numbers to use for this?

Thanks

1 Like

Subtract both os.time and if it is greater than or equal to 86400 seconds (one day) it means that you lost

local Now = os.time()
local Data = 0
if Now - Data >= 86400 then
   -- cancel
end
6 Likes

Uh yeah, I wasn’t asking for a Script, I was asking for the number but thanks.

That’s kind of all I was asking for

(Sorry if this is a stupid question)

Technically it’s a code fragment, but happy to help just the same :woman_shrugging:

2 Likes

So you reward them for playing that day, the next day comes while they’re still in-game, because the code only checked when they joined whether or not to reward them, it doesn’t trigger and they don’t get rewarded.
I would say you need an event to trigger when the next day occurs and reward those who are in-game.

I would have to do constant checking for that for when the time changes, and if there are many players with this, wouldn’t that cause a bit of issues?

Should I handle these Events on the Client and then Fire to the Server when the Time is reached?

I was thinking to have a server script loop by the second and check if the day passed yet. So

while wait(1) do
  if (time has passed) then
    -- reward players currently in server --
  end
end

tbh I don’t know how good of an idea this is.
You could also do reward player → wait minimum of 12 hrs and for next day to come.

Honestly don’t know how good this would be cause I just thought of something different but it could be good.

When the play joins the game, or when they claim the reward, check the time using the code fragment marked as solution, then you can just spawn wait the difference between the two times before updating the thing (you would probably want to do that on the client), once the wait is over fire a remote event (confirm it’s actually over and an exploiter didn’t just fire it) then allow the player to collect again

1 Like

I only have a question, wouldn’t thsi make the player have to join in less than 24 hours? That wouldn’t work theoretically, because the player would have to join befor 24 hours, I think instead you would need to check 48 hours, as that’s the end of the second day, and that’s when you want to not reward the player, so the number should be:
172800, and the script:

local Now = os.time()
local Data = 0
if Now - Data >= 172800 then
   -- cancel
end

It’s a daily reward, they should be claimed after 1 day, 24 hours, or 86400 seconds. I don’t get why you are trying to make the daily reward system a 2 day (48 hour) cooldown

No, he wants taht after the 24 hours you are able to claim the reward, for taht the number is right, but he also wanted that if you dot. Get the reward in time, it eliminates itself, which for that would be 48 hours after you got the last reward

Aha, I get what you’re saying now but instead of hardcoding it you should multiply the 86400 by the number of missed days and check the last claimed time against that

1 Like

Okay, that’s effectively a better idea, I’m not a Programmer so I don’t know much of these things :sweat_smile: Even though I’m good at theoretical things

1 Like

You guys should probably talk in a Message if you have Questions about stuff for People.

Well, it was relevant to the topic, we were suggesting ideas.

3 Likes

Just so you know, I wasnt asking how to Handle a Daily Rewards system as I already how to to do it, I was asking what number should I be using to check when to cancel their streak, because the results vary.

The only reason I gave the other person the Solution is because it had that.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.