Hello basiclly what I do like to ask is in the title. I already tried a solution with datastore cause it takes everytime the datastore but due to queue this won't work and I don't have a idea.
Claim script:
local DataRow = game.ReplicatedStorage.GetDataRow:InvokeServer()
local sec = 0
local hours = 0
local mins = 0
function Calculate()
local data = game.ReplicatedStorage.GetData:InvokeServer()
if data == 0 then
data = os.time()
data = data - 86500
end
local TimeNow = os.time()
print("working")
local timesincelastclaim = TimeNow - data
if timesincelastclaim >= 60 then
repeat
timesincelastclaim = timesincelastclaim -60
mins = mins +1
print(mins)
until timesincelastclaim < 60
end
if mins >= 60 then
repeat
mins = mins -60
hours = hours +1
until mins < 60
end
sec = timesincelastclaim
if sec == 60 then
sec = 00
end
print(hours)
end
if DataRow == "" or DataRow == nil or DataRow == 0 then
DataRow = 1
end
Calculate()
if hours >= 48 then
DataRow = 1
end
Calculate()
if hours >= 48 then
DataRow = 1
end
script.Parent.TextButton.MouseButton1Click:Connect(function()
if DataRow == "" or DataRow == nil or DataRow == 0 then
DataRow = 1
end
print("pressed")
Calculate()
print("pressed")
if hours >= 24 then
game.StarterGui:SetCore("SendNotification", {
Title = "Daily Reward",
Text = "You claimed your daily reward!",
Image = "rbxassetid://3593135345"
})
local saveofdatarow = DataRow
DataRow = DataRow * saveofdatarow
local MoneyToAdd = 100 * DataRow
DataRow = saveofdatarow +1
game.ReplicatedStorage.SetDataRow:InvokeServer()
script.Parent.Plus.Text = "+ "..MoneyToAdd.." Money"
script.Parent.TreasureChestOpen.Visible = true
script.Parent.TreasureChest.Visible = false
repeat
wait(0.08)
script.Parent.Plus.TextTransparency = script.Parent.Plus.TextTransparency - 0.1
until script.Parent.Plus.TextTransparency < 0.1
wait(5)
script.Parent.TreasureChestOpen.Visible = false
script.Parent.TreasureChest.Visible = true
repeat
wait(0.08)
script.Parent.Plus.TextTransparency = script.Parent.Plus.TextTransparency + 0.1
until script.Parent.Plus.TextTransparency > 0.9
game.ReplicatedStorage.SetData:InvokeServer(time.os())
else
game.StarterGui:SetCore("SendNotification", {
Title = "Daily Reward",
Text = "You can't claim it now!",
Image = "rbxassetid://3592767549"
})
end
end)
That's the text script:
local Hours = 23
local Mins = 60
local Secs = 59
local sec = 0
local hours = 0
local mins = 0
function Calculate()
local data = game.ReplicatedStorage.GetData:InvokeServer()
if data == 0 then
data = os.time()
data = data - 86500
end
local TimeNow = os.time()
print("working")
local timesincelastclaim = TimeNow - data
if timesincelastclaim >= 60 then
repeat
timesincelastclaim = timesincelastclaim -60
mins = mins +1
print(mins)
until timesincelastclaim < 60
end
if mins >= 60 then
repeat
mins = mins -60
hours = hours +1
until mins < 60
end
sec = timesincelastclaim
if sec == 60 then
sec = 00
end
print(hours)
end
Calculate()
while wait(1) do
if hours >= 24 then
script.Parent.Text = "Available to claim! 00:00:00 time left!"
else
Hours = Hours - hours
print(mins)
Mins = Mins -mins
Secs = Secs - sec
if Secs == 60 then
Secs = 00
end
script.Parent.Text = "Available to claim in "..Hours..":"..Mins..":"..Secs
Hours = 23
Mins = 60
Secs = 60
hours = 0
mins = 0
sec = 0
Calculate()
end
end
And the data store script:
local event1 = game.ReplicatedStorage.GetData
local event2 = game.ReplicatedStorage.GetDataRow
local event3 = game.ReplicatedStorage.SetData
local event4 = game.ReplicatedStorage.SetDataRow
local data1 = game:GetService("DataStoreService"):GetDataStore("Data1")
local data2 = game:GetService("DataStoreService"):GetDataStore("Data2")
event1.OnServerInvoke = function(player)
local id = player.UserId
local datasave = data1:GetAsync(id) or 0
print(datasave)
return datasave
end
event2.OnServerInvoke = function(player)
local id = player.UserId
local datasave = data2:GetAsync(id) or 0
return datasave
end
event3.OnServerEvent:Connect(function(player, val)
print(val)
local id = player.UserId
data1:SetAsync(id, val)
end)
event4.OnServerEvent:Connect(function(player, val)
print(val)
local id = player.UserId
data2:SetAsync(id, val)
end)
Thanks for ideas/solutions.

2 comments
dude whatever ur doing just save the tick and subtract it by the tick when the player gets back then if its equal to the amount of time spent, then reward the player stuff...
Also if it doesnt work cuz of the que, dont save data too often, save it when the player is being removed