I dont even know how to explain my problem…
So I am currently working on daily reward system. Of course, the time should be saved and theres the problem. I currently have 4 gifts and for some reason, they sometimes just get a wrong “status” which is just not making any sense. This especially happens when the timer of one reward is ready and another one was ready before. Than the old one switches mostly to status = countdown again, whuile the new one works. Its just so weird and I dont know where I should even start searching the error.
Thanks to everyone having the will to read whats coming now…:
LOCAL SCRIPT:
event.OnClientEvent:Connect(function(result)
for i, v in pairs(tools:GetChildren()) do
local reward = scrollFrame.Blue:Clone()
reward.Name = v.Name
reward.Visible = true
reward.Active = true
reward.Parent = scrollFrame
local seconds = v.Values.SpecialValues.Seconds.Value
local minutes = v.Values.SpecialValues.Minutes.Value
local hours = v.Values.SpecialValues.Hours.Value
local rewIsClaiming = v.Values.SpecialValues.Claimed.Value
local rewReady = v.Values.SpecialValues.Ready.Value
local rewMax = v.Values.SpecialValues.MaxNum.Value
local rewClaimed = reward.Claimed
local rewCounter = reward.Background.Bottom.Timer
local rewBar = reward.Background.Bottom.GreenTimer
local rewDescribe = reward.Background.Reward.HowMuch
local found = false
if result ~= nil then
for s, r in pairs(result) do
if s == v.Name then
found = true
seconds = r["seconds"]
minutes = r["minutes"]
hours = r["hours"]
if r["status"] == "claimed" then
rewIsClaiming = true
rewReady = false
rewClaimed.Visible = true
rewCounter.Text = "CLAIMED"
rewBar.Size = UDim2.fromScale(1, 1)
elseif r["status"] == "ready" then
rewReady = true
rewIsClaiming = false
rewCounter.Text = "READY"
rewBar.Size = UDim2.fromScale(1, 1)
end
end
if found == false then
result[v.Name] = {
["name"] = v.Name,
["seconds"] = seconds,
["minutes"] = minutes,
["hours"] = hours,
["status"] = "cooldown"
}
else
found = false
end
end
else
result = {}
result[v.Name] = {
["name"] = v.Name,
["seconds"] = seconds,
["minutes"] = minutes,
["hours"] = hours,
["status"] = "cooldown"
}
end
rewMax = (seconds+(minutes*60)+(hours*3600))
local tine = coroutine.create(function()
repeat
task.wait(1)
seconds -= 1
if seconds < 1 and minutes > 0 then
minutes -= 1
seconds = 60
if result ~= nil then
for _,r in pairs(result) do
if r["name"] == v.Name then
r["seconds"] = seconds
r["minutes"] = minutes
r["hours"] = hours
r["status"] = "cooldown"
end
end
end
print(result)
Saving("timesave", v.Name, result)
end
if minutes == 0 and hours > 0 then
hours -= 1
minutes = 60
end
rewBar:TweenSize(UDim2.new(rewBar.Size.X.Scale + (1/rewMax), 0, rewBar.Size.Y.Scale, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.1, false)
rewCounter.Text = hours .." : "..tostring(minutes).." : "..tostring(seconds)
until
minutes == 0 and seconds <= 0 and hours == 0 or buyed == true
if minutes == 0 and seconds < 1 then
rewReady = true
rewCounter.Text = "READY"
notification.Visible = true
notification.Amount.Text += 1
for s,r in pairs(result) do
if s == v.Name then
r["seconds"] = 0
r["minutes"] = 0
r["hours"] = 0
r["status"] = "ready"
end
end
Saving("ready", v.Name, result)
elseif buyed == true and rewIsClaiming == false then
rewIsClaiming = true
rewReady = false
rewClaimed.Visible = true
rewCounter.Text = "CLAIMED"
if result ~= nil then
for s,r in pairs(result) do
if s == v.Name then
r["seconds"] = 0
r["minutes"] = 0
r["hours"] = 0
r["status"] = "claimed"
end
end
end
print(result)
Saving("purchasing", v.Name, result)
seconds = 0
minutes = 0
hours = 0
task.wait(1)
rewBar.Size = UDim2.fromScale(1, 1)
end
end)
if rewIsClaiming == false and rewReady == false then
print("start".. v.Name)
coroutine.resume(tine)
end
rewDescribe.Text = v.Name
reward.Background.MouseButton1Click:Connect(function()
if rewReady == true and rewIsClaiming == false then
rewIsClaiming = true
rewClaimed.Visible = true
rewCounter.Text = "CLAIMED"
seconds = 0
minutes = 0
hours = 0
if result ~= nil then
for _,r in pairs(result) do
if r["name"] == v.Name then
r["seconds"] = 0
r["minutes"] = 0
r["hours"] = 0
r["status"] = "claimed"
end
end
end
Saving("claiming", v.Name, result)
if tonumber(notification.Amount.Text) >= 2 then
notification.Amount.Text -= 1
else
notification.Amount.Text = 0
notification.Visible = false
end
task.wait(1)
rewBar.Size = UDim2.fromScale(1, 1)
end
end)
end
end)
SERVER SCRIPT:
local dataStoreService = game:GetService("DataStoreService")
local store = dataStoreService:GetDataStore("Store7")
local rep = game:GetService("ReplicatedStorage")
local toolsFolder = rep.RewTools
local event = rep.RewardEvent
game.Players.PlayerAdded:Connect(function(plr)
local succ, result = pcall(function()
return store:GetAsync(plr.UserId)
end)
if succ then
event:FireClient(plr, result)
print(result)
end
if result ~= nil then
for i, r in pairs(result) do
if r["status"] == "claimed" then
print("yaY")
for i, v in pairs(toolsFolder:GetChildren()) do
if v.Name == r["name"] then
local t = v:Clone()
t.Parent = plr.Backpack
local t2 = v:Clone()
t2.Parent = plr.StarterGear
end
end
end
end
end
end)
event.OnServerEvent:Connect(function(plr, arg, tool, tab)
if arg == "purchase" or arg == "claiming" then
for i, v in pairs(toolsFolder:GetChildren()) do
if v.Name == tool then
local t = v:Clone()
t.Parent = plr.Backpack
local t2 = v:Clone()
t2.Parent = plr.StarterGear
end
end
local succ, err = pcall(function()
store:SetAsync(plr.UserId, tab)
end)
print(tab)
elseif arg == "timesave" or "ready" then
local succ, err = pcall(function()
store:SetAsync(plr.UserId, tab)
end)
print(tab)
end
end)
WHEN LEAVING AND ENTERING GAME:
Thanks for everyone replying!