Hey, I have a bug with my daily chest, it is suppose to be 12 hours but it comes up as 350 hours, No errors too, any fixes?
ServerScript:
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={}
--[[]]--
local ChestSettings={
['ClaimTime']=(12*60*60);
['Reward']=1_000;
['CurrencyName']="Credits";
['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")
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
else Timings[Player.Name]=0
end
if not ChestSettings.CreateNewCurrency then return end
local leaderstats=Instance.new('Folder')
leaderstats.Name="leaderstats"
leaderstats.Parent=Player
local currency=Instance.new('IntValue')
currency.Name=ChestSettings.CurrencyName
currency.Parent=leaderstats
local cd
local s,e=pcall(function()
cd=CurrencyStore:GetAsync(Player.UserId)
end)
if s and cd then
currency.Value=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.leaderstats[ChestSettings.CurrencyName].Value)
end)
if not Success then warn(Errormsg) else print("Saved Currency") 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("leaderstats") or Client:FindFirstChild("Leaderstats") 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)
return clock
end
game:BindToClose(function()
if game["Run Service"]:IsStudio() then
task.wait(1)
end
end)
ClientScript:
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="Touch to Claim"
TimeText.Parent.Time.TextColor3=Color3.fromRGB(61, 255, 90)
end
local function Decrementation(LastClaimTime)
if DeductRender then DeductRender:Disconnect() DeductRender=nil end
LastTime=0
TimeText.Parent.Title.Text="Chest Available In"
TimeText.Parent.Time.TextColor3=Color3.fromRGB(255, 180, 74)
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~="Touch to Claim" then
return
end
Debounce=true
local Response=ReplicatedStorage.ChestRemotes.Claim:InvokeServer()
if Response then
Decrementation(Response)
local function AnimateModel()
for z, t in pairs(Pad.Parent.ChestModel:GetChildren()) do
local Primary=t
local Origin=Primary.Position
local a=game.TweenService:Create(Primary,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Position=Vector3.new(Origin.X,Origin.Y+4,Origin.Z)})
a.Completed:Connect(function()
game.TweenService:Create(Primary,TweenInfo.new(0.7,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out,0,false,0),{Position=Vector3.new(Origin.X,Origin.Y,Origin.Z)}):Play()
end)
a:Play()
end
end
AnimateModel()
script['Effect']:Clone().Parent=Player.PlayerGui
script['SFX']:Play()
end
task.wait(2) Debounce=false
end)
--[[]]--
My Remote Functions: