Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Daily Reward System return a table. How to get the countdown?

I posted this not long time ago, and i received this script right here. I edited him a little bit for my use. But now, i have some questions about it. I'd like to create a UI with the amount of time before the reward. So i tried to send back the value of the PlayerData to get the time, but since she send me this in the output.

function: 16E5BAC4

--< Services
local PlayerService = game:GetService('Players')
local DataStoreService = game:GetService('DataStoreService')

--< Variables
local DailyRewards = DataStoreService:GetDataStore('dailyRewards')

local RewardTime = 24 -- One day
local RewardAmmount = 50 -- They get 50 cash 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 Cash = Instance.new('IntValue', ls)
	Cash.Name = 'Cash'
	Cash.Value = SessionData[Player]['Cash']
	
	local PlayerData = nil
	
	pcall(function() -- No errors pls
		PlayerData = DailyRewards:GetAsync('player_' .. Player.UserId)
	end)
	
	if PlayerData then
		if ((os.time() - PlayerData) / (60 * 60)) >= RewardTime then
			Cash.Value = PlayerData + RewardAmmount
			DailyRewards:SetAsync(Player.UserId, os.time())
		else
			Cash.Value = PlayerData
		end
	else
		DailyRewards:SetAsync(Player.UserId, os.time())
	end
end)

3 comments

0

os.time()

0

dude its easy just put the vector7 in the script and let the time center run for a while !

0

Vector7? This is not exist (Vector2, Vector3)

1 answer

idk about your code but here's what you should do

local DataStoreService = game:GetService('DataStoreService')
local DailyRewards = DataStoreService:GetDataStore('dailyRewards')

game.Players.PlayerAdded:Connect(function(plr)
local currentDay =  math.floor(os.time()/86400)
local key = plr.UserId
if  DailyRewards:GetAsync(key) then --checks if there is any saved values
local oldDay = DailyRewards:GetAsync(key) 
if oldDay < currentDay then
-- give your reward
end
end
DailyRewards:SetAsync(key, currentDay) 
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.