This is not a request! Tell me how to start.
Thanks for helping me!
This is not a request! Tell me how to start.
Thanks for helping me!
There are two possible things you might be wanting to do:
In both methods you need to log when you awarded the player something last. You will need to store this value in a data store, where the key is the user's id (never user their name, which can change), and where the value is the login date (you should use os.time over tick() when storing time (the link explains why and also has some other useful functions).
You cannot run a script for every player in existence every day (if for no other reason than you don't have enough data store requests for the millions of possible players that might enter your game; see the limits in the Data store article). The better solution is to have a script that runs when a player enters your game. When that happens, calculate the time since they last logged in. You can do a few different things then:
You might choose to set the time to the current day, excluding hours/minutes/etc, so that when someone logs in at slightly different times each day (ex 3pm one day, 4pm the next, then 2pm after that), they'll still get the login, even though it hasn't been 24 hours since the last login.
If they have logged in too early, you might periodically check to see if they can be awarded for logging in yet (until they leave or until you can award them something), or you might just ignore this case.
You want to look into time in roblox, and storing userdata. If you write to a userfile the time and date of the last time they received the award, you can later check to see how much time has passed, and if enough has, allow them to receive the award again.
A starting place to see if their eligible is
local currentTime = tick() --current time in Unix
timeOfLastAwardClaim --The last time the gift was claimed in unix time, gotten from server storage
if timeOfLastAwardClaim + 86400 > currentTime then --86400 is one day in unix time
--Give award!
timeOfLastAwardClaim = currentTime
--Store timeOfLastAwardClaim back into server storage
end
Articles on unix time: https://en.wikipedia.org/wiki/Unix_time
Storing userdata: http://wiki.roblox.com/index.php?title=Saving_Player_Data
Good luck!
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
tick() can be different on different systems, see http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#os.time
Ah, just read through the full article. Nice job catching that :)