Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 5 years ago
Edited 5 years ago

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)
0
os.time() DevingDev 346 — 5y
0
dude its easy just put the vector7 in the script and let the time center run for a while ! BlackCheap 14 — 5y
0
Vector7? This is not exist (Vector2, Vector3) NiniBlackJackQc 1562 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
Ad

Answer this question