How to reset daily rewards on specific time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Okay so I am new about scripting and just started learning about os.time,os.clock etc and want to reset daily rewards on a specific time like let’s say UTC+2 9am
  2. What is the issue? Include screenshots / videos if possible!
    I Don’t know how to do it
    I made a basic script that resets the daily reward for client every 24 hours after player gets it
    But I am trying to turn it to server daily reset
DailyReward.Touched:Connect(function(hit)
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if os.time() >= (player.DailyReward.Value) 	then
			player.DailyReward.Value = os.time() + 86400
		end
	end
end)
  1. What solutions have you tried so far?
    I tried checking youtube and previous post but have no idea about how to reset every daily cooldowns at one time for server not client
1 Like

Yeah I still wonder the answer

1 Like

You can use a remote event to send to tell the server that they got the reward.

But you could also do this all on the server too no?

I don’t know if the answer is no or yes. like I said I just started learning about os.time so, I don’t know much how to use os.time for server daily reset. all post I saw about os.time was for adding cooldowns like the code I write

what is the point of this? like how telling the server they got the reward will help with daily reward?
I feel like I couldn’t explain my question
like if a player get’s the daily chest at 16.00 I want player to reclaim the chest at 00.00
and if another player get’s the daily chest at 14.00 I also want that player to be able to reclaim the chest at 00.00

You should learn about RemoteEvents, and use them to handle the part:

if os.time() >= (player.DailyReward.Value) then
	player.DailyReward.Value = os.time() + 86400
end

On a ServerScript. If you have a datastore already that can remember the daily reward or keep track of player’s money, you could implement the time for daily reward there.

My bad, I thought you were trying to comunicate from client to server, ideally this should be done on the server

Now this I can answer:

DailyReward.Touched:Connect(function(hit)
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if math.floor(os.time()/86400) > (player.DailyReward.Value) then
			player.DailyReward.Value = math.floor(os.time()/86400) -- gets the day
		end
	end
end)

I guess only way to detech if it is working or not. is waiting 2 hours and 55 minutes (which is time remained until new day acording to os.time)
Thanks! I will inform later if it is working or not!

You can manually set os.time() by putting a parameter in the function, here are the docs.

1 Like

I just tested and yeah it work’s Thanks. but I wondered somethink else, how can change the reset time to 01.00 not 00.00 adding a hour and changing os.time to (90000) will make it 25 hours I am confused about this a little bit

Follow the format in the docs;

os.time{
    year=2023, month=4, day=6,  -- Date components
    hour=3, min=0, sec=0  -- Time components
} 
-- if time.os returned a time on 4/6/2023 (mm/dd/yyyy) at 2:00am or 2:00
-- this would return a time 1 hour after then, with an hour of 3 or 3:00am 
1 Like

I understand that part but this means if time changes a day later and becomes 4/7/2023 it won’t return a time 1 hour after

I feel like a stupid when a person clearly explains something to me with documents and I can’t still figure out things…

For this you want to check if the saved os.time is smaller than the current time - a day.

if tonumber(TIME_DATA) < os.time() - 86400 then

1 Like

You probably don’t want to do that because a person who joins 5 minutes before 0:00 could get the daily reward twice in 5 minutes.

1 Like

this is totally ok. I would rather this

Why would you want it to be like that?

this is a diffucult question why shouldn’t I want it like that?
by the way. is this how should script should look like to set reset time to 01.00?

DailyReward.Touched:Connect(function(hit)
	print(math.floor(os.time()/86400))
	local SavedTime =(os.time{
		year=2023, month=4, day=7,  -- Date components
		hour=1  -- Time components
	})
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if SavedTime < os.time() -86400 then
			SavedTime = os.time()
		if math.floor(os.time()/86400) > (player.DailyReward.Value) then
		--if os.time() >= (player.DailyReward.Value) 	then
			player.DailyReward.Value = math.floor(os.time()/86400)
              end
         end

I am not sure about if this one is correct

Try to get rid of the year month and day part in os.time and see what happens. Also you have to save it with DataStoreService.

Also you should probably remove the os.time()/86400 part since it prints 19650 in the console for me and thats way larger than 24.

Yeah I am really confused rightnow
I thought it would give 1 hour later of the date I put there

DailyReward.Value
part is already a saved value if you are talking about it?

1 Like

If you set the value with os.time by touching the part it won’t save once the player leaves. Which is why you have to use DataStoreService which is a service specifically made for saving player data to save it.