Why this script not work?:( It's a beta Daily Reward system, to get the countdown..
In ServerScript:
--< Services
local PlayerService = game:GetService("Players")
local RStorageService = game:GetService('ReplicatedStorage')
local DataStoreService = game:GetService("DataStoreService")
--< Variables
local DailyRewards = DataStoreService:GetDataStore("dailyRewards")
local RewardTime = 24 -- one day
local RewardAmmount = 50 --they get 50 money each day
local SessionData = {}
--< Event
PlayerService.PlayerAdded:Connect(function(player)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = player
SessionData[player] = {}
SessionData[player]["Cash"] = 100
local money = Instance.new("IntValue", ls)
money.Name = "Cash"
money.Value = SessionData[player]["Cash"]
local playerData = nil
pcall(function() -- no errors pls
playerData = DailyRewards:GetAsync("player_" .. player.UserId)
end)
if playerData then
if ((tick() - playerData) / (60 * 60)) >= RewardTime then
money.Value = playerData + RewardAmmount
DailyRewards:SetAsync(player.UserId, tick())
else
money.Value = playerData
end
else
DailyRewards:SetAsync(player.UserId, tick())
playerData = DailyRewards:GetAsync("player_" .. player.UserId)
end
require(script.Parent.ModuleScript):ConvertTime((tick() - playerData))
end)
In ModuleScript:
local module = {}
local Type = 0
function module:ConvertTime(t)
-- Variables
-- Sec, Min, and Hour equations I actually got off of Google. Everything else was written by me
local sec = math.floor((t%60))
local min = math.floor((t/60)%60)
local hour = math.floor((t/3600)%24)
-- Set time
sec = tostring((sec < 10 and "0" or "") .. sec)
min = tostring((min < 10 and "0" or "") .. min)
-- Ternary operators FTW. Helps get rid of 'if then' stuff. Actually learned this off of Java programming: z = (x == y ? "Yes" : "No")
hour = ((Type == 1 and hour < 10 and "0" or "") .. tostring(Type == 0 and (hour == 0 and 12 or hour > 12 and (hour-12) or hour) or hour))
-- Colon, (space if 12 hr clock)
local c, s = ":",(Type == 0 and " " or "")
return (hour .. c .. min .. (c .. sec or "") .. s)
end
return module
I have the impression that nobody will answer me. (Again...)
RePost #3

1 comment
That server script is a copy and paste from the Roblox Wiki.