How do you make a daily reward system. (Everyday it gives you 'x' amount of game currency)
You can save the the time since their last login in the datastore. See how much time has passed since his last login. This is just some help. Try to learn.. read.. this is just to help you getting started.
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "LastLogin" ) --Get the DataStore. |
02 |
03 |
04 | Game.Players.PlayerAdded:connect( function (Player) |
05 | wait() |
06 | local LastLogin = DataStore:GetAsync(Player.userId) |
07 | if LastLogin then |
08 | local Seconds = os.time()-LastLogin |
09 | local Minutes = Seconds/ 60 |
10 | local Hours = Minutes/ 60 |
11 | print ( "It has been: " ..Hours.. " hours Since your last reward" ) --This just prints how much time has passed since your last reward. |
12 | if Hours > = 24 then |
13 | print ( "You get a daily login award" ) --This happens if 24 hours has passed since his last login so he gets an award! |
14 | DataStore:SetAsync(Player.userId,os.time()) |
15 | end |
16 | else |
17 | DataStore:SetAsync(Player.userId,os.time()) |
18 | end |
19 | end ) |
I have tried something for my old game but I am not sure if it works. In case you want to add daily cash.
1 | local Humanoid = script.Parent.Humanoid |
2 | function PwntX_X() |
3 | local tag = Humanoid:findFirstChild( "creator" ) |
4 | if tag ~ = nil then |
5 | if tag.Value ~ = nil then |
6 | local Leaderstats = tag.Value:findFirstChild( "leaderstats" ) |
7 | if Leaderstats ~ = nil then |
8 | Leaderstats.Cash.Value = Leaderstats.Cash.Value + 250 |
9 | wait ( ) -- type in the parenthesis the seconds of a day cause I am bored to estimate now xD and do this a bunch of time, but each times you can change the cash value that is being given. Tell me if it worked. |