Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i do this?

I was wondering how some games have like "You got 50 cash for joining! Join again in 5 hours to get more!" because i was wanting to do that. So obviously you dont use:

wait(2500)
Cash.Value = Cash.Value + 50

Right?

Help please.

2 answers

✓ Accepted answer

Well you are right in a sense. Most games use os.time() to fetch Server-Wide times since os.time() is never changeable.

What is os.time()?

os.time() is the number of seconds that have passed since epoch

What is epoch?

https://en.wikipedia.org/wiki/Epoch

So by using the seconds since epoch, you can make a simple script that when 2500 more seconds since epoch pass, it rewards the players with a certain amount of cash. I cannot provide a script since I don't know much more about this, but I can provide some simple variables based off of os.time()

timezoneoffset = -5 --How far off you are from UDC

t = os.time() -- seconds since epoch
year = t / (60 * 60 * 24 * 365.25) -- years since epoch
currentyear = math.floor(year) + 1970 -- current year
print(currentyear)
day = math.floor(t / (60 * 60 * 24)) -- Days since Epoch
print(day)
hour =  math.floor(math.fmod(t,(60 * 60 * 24)) / (60 * 60)) -- hours since midnight today
print(hour)
localhour = hour + timezoneoffset -- hour adjusted for time zone
print(localhour)

You're correct -- that's not how you do it.


I'm not gonna code this for you, but I'll tell you how to do it and give some useful links.


Use PlayerAdded to detect when someone joins. Then use DataStores to save all relevant information. This should include the time they joined, which you can get using os.time. Then, when they join again, first get their data (if they have any), then subtract the time that they last joined from the current time. This will give you how long the 'gap' between visits was, and then you can easily make sure that it's long enough to get another reward.

This discussion is preserved as it was. New answers, comments, and votes are closed.