Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Daily reward system. Money duplicating instead of adding?

Asked by 4 years ago

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

01local DataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
02 
03local hourWait = 23
04 
05 
06script.Parent.Clicker.ClickDetector.MouseClick:Connect(function(player)
07 
08    local timeNow = os.time()
09 
10    local data
11 
12    pcall(function()
13        data = DataStore:GetAsync(player.UserId.."Chest01") --Change
14        print("Getting Data")
15    end)
View all 41 lines...
0
Please trim your code. See https://idownvotedbecau.se/TooMuchCode . Also, is this your code? User#30567 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I cant see anything wrong but it sound like the first time you click the chest it gives you the reward and then waits for you to be able to click the chest again. Then when you click it the second time the script runs (as if its the first time you've clicked it) and the script also runs because the wait which begun when you first clicked the chest has ended.

011st Click:
02Script 1 runs
03Script 1 wait begins
04 
052nd Click:
06Script 1 wait ends
07Script 1 runs
08Script 1 wait begins
09Script 2 runs
10Script 2 wait begins
11 
123rd Click:
13Script 1 wait ends
14Script 1 runs
15Script 1 wait begins
View all 22 lines...

You could test this by having it print a number when you click the chest and then when all the code is finished saying i = i+1 to see if the next time you click the chest you get 2 or 2 , 1 as seperate outputs (or ever just 1,1 tbh...)

The use of debounce or making sure the script isn't both listening and waiting for you to click at the same time might help?

Sorry I can't be of much help :/

0
sorry for the formatting it didnt look like that at the time of typing.. AlexTheCreator 461 — 4y
Ad

Answer this question