Daily reward system doesn't work

Hey,

I tried to make daily reward system. It works normally… almost.
Timer shows over 1500 hours. It has to be 24 hours.

I tried to fix that problem but it didn’t work. I also tried to find a way to solve it and I tried to say about this problem to Wheez, who made that code and the whole daily reward system. I made the same thing what he made in this video. I only changed values and objects for my game.

Here are my server and local scripts:

SERVER





local PlayersService=game:GetService('Players')
local DataStoreService=game:GetService('DataStoreService')
local DataStore=DataStoreService:GetDataStore(":ChestData")
local CurrencyStore=DataStoreService:GetDataStore(":Currency")
--[[]]--
local ReplicatedStorage=game:GetService('ReplicatedStorage')
local Timings={} -- Do Not Touch
--[[]]--
local ChestSettings={
	['ClaimTime']=(24*60*60); 
	['Reward']=1;
	['CurrencyName']="Dailyb";
	['CreateNewCurrency']=true;
}
--[[]]--
local function CanClaim(b)
	local Boolean=false
	if Timings[b.Name] then
		if (os.clock()-Timings[b.Name])>=ChestSettings.ClaimTime then
			Boolean=true
		end
	end
	return Boolean
end
local function SaveClaim(b,clock)
	local Success,Errormsg=pcall(function()
		DataStore:SetAsync(b.UserId,clock)
	end)
	if not Success then
		warn(Errormsg)
	else print("Saved Chest Claim for Player: " .. b.Name)
	end
end
PlayersService.PlayerAdded:Connect(function(Player)
	local ChestData=Instance.new('BoolValue')
	ChestData.Name="ChestData"
	ChestData.Parent=Player
	local OldData
	local Success,Errormsg=pcall(function()
		OldData=DataStore:GetAsync(Player.UserId)
	end)
	if Success and OldData then
		local Difference=(os.clock()-OldData)
		Timings[Player.Name]=OldData
		print("Player " .. Player.Name .. " has been offline for " .. Difference .. " seconds.")
	else Timings[Player.Name]=0 
	end
	if not ChestSettings.CreateNewCurrency then return end
	local leaderstats=Player:WaitForChild("Boksit")
	local currency=leaderstats:FindFirstChild("Dailyb")
	
	local cd
	local s,e=pcall(function()
		cd=CurrencyStore:GetAsync(Player.UserId)
	end)
	if s and cd then
		currency.Value=cd
		print("Set currency for Player " .. Player.Name .. " to " .. cd)
	end
	ChestData.Value=true
end)
PlayersService.PlayerRemoving:Connect(function(Player)
	if Player:FindFirstChild("ChestData") and Player.ChestData.Value==true then
		if not ChestSettings.CreateNewCurrency then return end
		local Success,Errormsg=pcall(function()
			CurrencyStore:SetAsync(Player.UserId,Player.Boksit[ChestSettings.CurrencyName].Value)
		end)
		if not Success then warn(Errormsg) else print("Saved Currency for Player " .. Player.Name) end
	end
end)
ReplicatedStorage.ChestRemotes['ReturnStatus'].OnServerInvoke=function(Client)
	local PlayerTiming
	if Timings[Client.Name] then PlayerTiming=Timings[Client.Name] end
	
	return {CanClaim(Client),PlayerTiming,ChestSettings.ClaimTime}
end
ReplicatedStorage.ChestRemotes['Claim'].OnServerInvoke=function(Client)
	if not CanClaim(Client) then return end
	local Folder=Client:FindFirstChild("Boksit") or Client:FindFirstChild("boksit") or nil
	if Folder then
		Folder=Folder:FindFirstChild(ChestSettings.CurrencyName) or nil 
	end
	if Folder then
		Folder.Value+=ChestSettings.Reward
	else
		for a, b in pairs(Client:GetDescendants()) do 
			if b.Name==ChestSettings.CurrencyName then
				b.Value+=ChestSettings.Reward
				break
			end
		end
	end
	local clock=os.clock()
	Timings[Client.Name]=clock
	SaveClaim(Client,clock)
	print("Player " .. Client.Name .. " claimed a reward. New timing: " .. clock)
	return clock
end
game:BindToClose(function()
	if game["Run Service"]:IsStudio() then
		task.wait(1)
	end
end)

LOCAL SCRIPT:









local ReplicatedStorage=game:GetService('ReplicatedStorage')
local PlayersService=game:GetService('Players')
local Player=PlayersService.LocalPlayer
--[[]]--
repeat wait() until Player:FindFirstChild("ChestData") and Player['ChestData'].Value==true
repeat wait() until workspace:FindFirstChild("DailyChest") and workspace['DailyChest']:FindFirstChild("UI") and workspace['DailyChest']['UI']:FindFirstChild("BillboardGui") and #workspace['DailyChest']['UI']['BillboardGui']:GetChildren()==2
--[[]]--
local TimeText=workspace['DailyChest']['UI']['BillboardGui']['Time']
local Response=ReplicatedStorage.ChestRemotes.ReturnStatus:InvokeServer()
if not Response then
	repeat
		Response=ReplicatedStorage.ChestRemotes.ReturnStatus:InvokeServer()
		task.wait()
	until Response
end
--[[]]--
local DeductRender,LastTime;
--[[]]--
function Format(Int)
	return string.format("%02i", Int)
end
function Convertseconds(Seconds)
	local Minutes = (Seconds - Seconds%60)/60
	Seconds = Seconds - Minutes*60
	local Hours = (Minutes - Minutes%60)/60
	Minutes = Minutes - Hours*60
	return Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end
local function Available()
	if DeductRender then DeductRender:Disconnect() DeductRender=nil end
	LastTime=0
	TimeText.Parent.Title.Text="Claim now!"
	TimeText.Parent.Time.TextColor3=Color3.fromRGB(0, 255, 191)
end
local function Decrementation(LastClaimTime)
	if DeductRender then DeductRender:Disconnect() DeductRender=nil end
	LastTime=0
	TimeText.Parent.Title.Text="DailyKiulu available in"
	TimeText.Parent.Time.TextColor3=Color3.fromRGB(255, 255, 255)
	local function UpdateText()
		TimeText.Text=Convertseconds(Response[3]-(os.clock()-LastClaimTime))
	end
	DeductRender=game:GetService('RunService').RenderStepped:Connect(function()
		if (os.clock()-LastTime)>=1 then
			if (Response[3]-(os.clock()-LastClaimTime))>=1 then
				UpdateText()
			else
				if DeductRender then DeductRender:Disconnect() DeductRender=nil end
				UpdateText()
				Available()
			end
		end
	end)
end
if Response[1] then
	Available()
else Decrementation(Response[2])
end




local function TweenDown()
	if workspace['DailyChest']['UI']['TweenType'].Value=="Up" then
		workspace['DailyChest']['UI']['TweenType'].Value="Down"
		game.TweenService:Create(workspace['DailyChest']['UI']['BillboardGui'],TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),{Size=UDim2.new(0,0,0,0)}):Play()
	end
end
local function TweenUp()
	if workspace['DailyChest']['UI']['TweenType'].Value=="Down" then
		workspace['DailyChest']['UI']['TweenType'].Value="Up"
		game.TweenService:Create(workspace['DailyChest']['UI']['BillboardGui'],TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size=UDim2.new(12,0,6,0)}):Play()
	end
end
game:GetService('RunService').RenderStepped:Connect(function()
	if not Player.Character then TweenDown() return end
	if not Player.Character:FindFirstChild("HumanoidRootPart") then TweenDown() return end
	local Magnitude=(Player.Character.HumanoidRootPart.Position-workspace['DailyChest']['UI'].Position).Magnitude
	if Magnitude>30 then
		TweenDown()
	else TweenUp()
	end
end)
local Pad=workspace:WaitForChild("DailyChest"):WaitForChild("Pad")
local Debounce=false
Pad.Touched:Connect(function(Hit)
	if not Player.Character then return end
	if Hit.Parent~=Player.Character then return end
	if Debounce==true then return end
	if TimeText.Parent.Title.Text~="Claim now!" then
		return
	end
	Debounce=true
	local Response=ReplicatedStorage.ChestRemotes.Claim:InvokeServer()
	if Response then
		Decrementation(Response)

		script['Effect']:Clone().Parent=Player.PlayerGui
		script['SFX']:Play()
	end
	task.wait(2) Debounce=false
end)
--[[]]--

I’m really glad if you can help me. :slight_smile:
This is my first post so if I do something wrong, tell please…

1 Like

You’re not supposed to use os.clock() for this. Instead, use os.time().