How can I create a daily chest system?

It doesn’t automatically run he’s saying that when the player joins back to compare the current time to the time saved when he left/opened the daily reward

Alright I have read the documentation but still kinda confused. How will I be able detect when the player joined compared to the timer i have set.

Well if you save it with os.time() it stores the time in seconds so subtract that time by the current time (in seconds using os.time()) and then check if it’s less than or equal too 86,400 (which is 24 hours) if it is let them claim the reward again

Ok then, I will write some sample code, then get back to you. Also, how would you display the remaining time for you to open a chest, like a text label saying 24 hours left or something

Billboard GUI with a script that uses a remote event handled by the client

So no use of os.time()? how would I use the Remote Event

No you need the os.time() and datastore but your GUI would have a script that displays the saved time that the player collected their reward minus the current time. You would want to format it though.

How would I be able to format it though?

Check the dev forum I know there’s a post for that as I’ve used it in the past

I couldn’t find the one I was talking about but this seems like it should work just as well:

local TimeToStop = 86400 --Amount of seconds in one day (So it would be for daily)
function Format(Int)
	return string.format("%02i", Int)
end
function convertToHMS(Seconds)
	local Minutes = (Seconds - Seconds%60)/60
	Seconds = Seconds - Minutes*60
	local Hours = (Minutes - Minutes%60)/60
	Minutes = Minutes - Hours*60
	return Format(Hours)..":".. Format(Minutes)..":"..Format(Seconds)
end

Now all thats left to do is set the text to Format(TimeToStop)

Link to post:

Here’s a daily chest system I made a while ago. It doesn’t give money or anything but that should be simple to add into the script. Daily Chest - Roblox

That’s good but we’re also trying to teach him and not just supply him which is what the DevForum is about

Dissecting functional code is a great way to learn. He can look through it to see how I made mine and decide if he wants to use my design or create his own based on what he learns from my version.

1 Like

I know but explanation is also helpful too

os.time uses UTC so timezones won’t be a problem. Also, why not use os.time exclusively.

I would use os.time() along with a module script that contains every players last time they opened the chest. When they claim their reward you can check if enough time has passed. You can use a function like this:

local function GetTimeLeft(player, chestName)
	local startTime = chestTimes[player.UserId][chestName]
	if startTime then 
		local timePassed = os.time() - startTime
		local timeLeft = cooldown - timePassed
		
		return timeLeft
	elseif startTime == nil then
		return 0
	end
	return nil
end

Using a module script also allows your data store script to save it. To save data all you need to do is when they leave, save their section in the module script then remove it by setting it to nil.

Module would look something like:

chestTimes = {
    [UserId] = {
        DailyChest = 2343822
    }
}

I think the resources other people have sent, including you, are pretty good at explaining it. I’m just showing it to them in practice.

I looked through both the code and documentation and I seem to be getting a better understanding of os.time(). Thank you very much.

I’m glad it helped! Good luck with the rest of your project

My bad, you’re right! os.time would be fine then. Sorry for the confusion OP