Pretty sure my datastores messing up with. If I set the default data to be os.time() it changes everytime I rejoin, even tho every other value in the datastore saves
local Seconds = os.difftime(os.time(), Obby.Value)
local Minutes = Seconds / 60
if Minutes > 30 then
print('Can play the obby')
Obby.Value = os.time()
else
print('You have to wait ' .. Minutes .. ':' .. Seconds
end
In case you still didn’t get it working, this should work.
local lastObbyRun = os.time();
if os.difftime(os.time(), lastObbyRun) >= 60 * 30 then --os.difftime() takes the second value out of the first value. 60 seconds (1 minute) * 30 (minutes) or 1800 seconds.
print("Obby time!");
lastObbyRun = os.time();
else
local totalSeconds = os.difftime(os.time(), lastObbyRun);
local seconds = totalSeconds % 60;
local minutes = (totalSeconds - seconds) / 60;
print(string.format("No obby for you. You need to wait %02d:%02d", minutes, seconds));
--No obby for you. You need to wait 27:06
end;
That counts up tho. This is what I got on the client to show the countdown
while true do
if Obbies["Grass Obby"].Value == 0 then
Title.Text = 'Can play this obby'
Time.Text = 'NOW'
else
local totalSeconds = os.difftime(os.time(), Obbies["Grass Obby"].Value)
local seconds = totalSeconds % 60
local minutes = (totalSeconds - seconds) / 60
if minutes >= 30 then
Title.Text = 'Can play this obby'
Time.Text = 'NOW'
else
Title.Text = 'Can play this obby in'
Time.Text = string.format("%02d:%02d", minutes, seconds)
end
end
wait()
end
And so when the time has passed 30 minutes, it goes to ‘you can play’ and when i go to play, it starts the timer, but it’s counting up, instead of down
Not sure if your issue has been solved or not, but as for it counting down try subtracking totalSeconds from 30 minutes in seconds and then convert it to minutes + seconds
local totalSeconds = os.difftime(os.time(), Obbies["Grass Obby"].Value)
local CountdownSeconds = 1800 - totalSeconds
local seconds = CountdownSeconds % 60
local minutes = (CountdownSeconds - seconds) / 60
Fun fact that you may or may not know, In Soccer(football), the timer counts up instead of down!