local dailyRewardsDS = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
local hourWait = 0.1
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats
local timeNow = os.time()
local data
pcall(function()
data = dailyRewardsDS:GetAsync(plr.UserId .. "-DailyRewards")
print("Getting data")
end)
if data ~= nil then
local timeSinceLastClaim = timeNow - data
print("Time since last claim " .. timeSinceLastClaim)
if (timeSinceLastClaim / 3600) >= hourWait then
local reward = 50
local prompt = script.Parent
prompt.Trigged:Connect(function()
print("Reward claimed")
money.Value = money.Value + reward
dailyRewardsDS:SetAsync(plr.UserId .. "-DailyRewards", os.time())
end)
print("Player is not elegible right now")
end
else
print("New player")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data
pcall(function()
data = dailyRewardsDS:GetAsync(plr.UserId .. "-DailyRewards")
print("Getting the data")
end)
if data == nil then
pcall(function()
local timeVal = os.time()
dailyRewardsDS:SetAsync(plr.UserId .. "-DailyRewards")
end)
print("Saved because new player")
end
end)
It is not allowing me to subtract the current time from the data, anyone know why?
Error line: timeNow - data