Daily reward system. Money duplicating instead of adding?
Ok, so im a decent scripter but for the life of me I can't see my mistake here. I'm only posting part of this script.
The entire script runs!
The script is a daily reward system when clicking a chest on the map.
Problem:
the first time collecting runs smooth, second time running increases your money by thefirstcollection + thesecondcollection.
third time does first + second + third, essentially slowly accumulating.
aka if day one i gain 50, and i should gain 50 more on day two. its currently collecting both days together for a total of 100.
Can anyone see my mistake here? I'm assuming its how i data saved it but i've tried everything i can think of
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "DailyRewards" ) |
06 | script.Parent.Clicker.ClickDetector.MouseClick:Connect( function (player) |
08 | local timeNow = os.time() |
13 | data = DataStore:GetAsync(player.UserId.. "Chest01" ) |
20 | local timeSinceLastClaim = timeNow - data |
22 | print ( "Time since last claim" ..timeSinceLastClaim) |
24 | if (timeSinceLastClaim / 3600 ) > = hourWait then |
26 | local reward = math.random( 50 , 100 ) |
27 | game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward) |
29 | connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect( function (triggeringPlayer) |
30 | if triggeringPlayer = = player then |
31 | player.leaderboard.Money.Value = player.leaderboard.Money.Value + reward |
32 | DataStore:SetAsync(player.UserId.. "Chest01" ,os.time()) |
33 | script.Parent.Clicker.BillboardGui.TextLabel.Text = "You got " ..reward.. " Money!" |
35 | script.Parent.Clicker.BillboardGui.TextLabel.Text = "Come again in 24 hours" |
37 | script.Parent.Clicker.BillboardGui.TextLabel.Text = "" |
38 | connection:Disconnect() |