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
local DataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
local hourWait = 23
script.Parent.Clicker.ClickDetector.MouseClick:Connect(function(player)
local timeNow = os.time()
local data
pcall(function()
data = DataStore:GetAsync(player.UserId.."Chest01") --Change
print("Getting Data")
end)
if data ~= nil then
local timeSinceLastClaim = timeNow - data
print("Time since last claim"..timeSinceLastClaim)
if (timeSinceLastClaim / 3600) >= hourWait then
local reward = math.random(50,100)
game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
local connection
connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
if triggeringPlayer == player then
player.leaderboard.Money.Value = player.leaderboard.Money.Value + reward
DataStore:SetAsync(player.UserId.."Chest01",os.time()) --Change
script.Parent.Clicker.BillboardGui.TextLabel.Text = "You got "..reward.." Money!"
wait(2)
script.Parent.Clicker.BillboardGui.TextLabel.Text = "Come again in 24 hours"
wait(2)
script.Parent.Clicker.BillboardGui.TextLabel.Text = ""
connection:Disconnect()
end
end)
else

1 comment
Please trim your code. See https://idownvotedbecau.se/TooMuchCode . Also, is this your code?