Hello, I am trying to create a local 24 hour timer for each player. The timer should start when they first join the game. The goal of this timer is to give the player a free skip stage every 24 hours. I do not need help with making the skip stage work, just the timer. The timer should run for 24 hours, then the player should get a free skip. The timer should not restart until they use the free skip, but once they use it the 24 hours should start again. If anybody could help it would be greatly appreciated. I could give you access to the game if needed!
You could just store the last time they have skipped and compare it with the current time.
Hello! @Thenoob2pro_2022 here! Just to confirm with what you are saying, are you needing help on the scripting portion or the UI? Or both! I can help with both and is this something like the game Pet Sim X where every 5 minutes you get a prize just instead its a free stage every 24 hours?
Thanks! Hope to help you!
-Drew
@seancool07777’s answer would be your solution. To add on to that, you’ll want to use a DataStore to store an os.time() timestamp. When skipped, save the current timestamp and add 86,400 seconds to it (24 * 60 * 60). Then constantly compare the current time to that saved time and convert the time difference, which will be in seconds, into a different different format (such as seconds / 3600
to get the hour count). Allow the skip to work if either a saved time doesn’t exist or if the current time is greater than the saved time. Once skipped, set the new time as previously stated.
I do not need help with the UI, just the scripting! If you want, you can message me on roblox and I can add you to studio!
local Timer = 24 * 60 * 60 -- 24 hours in seconds
local startTime = os.time()
while true do
wait(1) -- wait for 1 second
local elapsedTime = os.time() - startTime
if elapsedTime >= Timer then
-- Timer has reached 24 hours, perform actions here
print("24 hours have passed!")
-- Reset the timer
startTime = os.time()
end
end