Hello there,
I have an issue with the datastore system in my daily-reward arrangement, by which the textlabel for the local player will not change according to the time remaining in my server-side script, and there are no errors in my output panel. It should work as I have the necessary remoteevents required to fulfil the operation.
To illustrate my situation, my output depicts the following:
Time since last claim 15502 - Server - Events:290
While the blank text (“…”) does not portray anything related to this value:
I have used AlvinBlox’s “How To Make A Daily Reward” video for reference.
Here are my scripts for critique:
Server
local RewardsDataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
local Duration = 24 -- Hours
local RewardsTable = {20, 20, 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 75, 75, 75, 100, 100, 200, 1000}
game.Players.PlayerAdded:Connect(function(Player)
local CurrentTime = os.time()
local Data
pcall(function()
Data = DataStore:GetAsync(Player.UserId.."-DailyReward")
print("Obtaining data...")
end)
if Data ~= nil then
print("Existing player")
local TimeSinceLastClaim = CurrentTime - Data -- In seconds
print("Time since last claim "..TimeSinceLastClaim)
if (TimeSinceLastClaim / 3600) >= Duration then
print("Player is able to claim Daily Reward")
local Reward = RewardsTable[math.random(1, #RewardsTable)]
game.ReplicatedStorage.PresentDailyReward:FireClient(Player, Duration, Reward)
local Connection
Connection = game.ReplicatedStorage.ClaimDailyReward.OnServerEvent:Connect(function(RequestingPlayer)
if RequestingPlayer == Player then
print("Reward Claimed!")
Player.Credits.Value = Player.Credits.Value + Reward
DataStore:SetAsync(Player.UserId.."-DailyReward", os.time())
Connection:Disconnect()
end
end)
else
print("Player is uneligible to receive Reward")
end
else
print("New player found")
local Reward = RewardsTable[math.random(1, #RewardsTable)]
game.ReplicatedStorage.PresentDailyReward:FireClient(Player, Duration, Reward)
local Connection
Connection = game.ReplicatedStorage.ClaimDailyReward.OnServerEvent:Connect(function(RequestingPlayer)
if RequestingPlayer == Player then
print("Reward Claimed!")
Player.Credits.Value = Player.Credits.Value + Reward
DataStore:SetAsync(Player.UserId.."-DailyReward", os.time())
Connection:Disconnect()
end
end)
end
end)
Local
local ShopGUI = script.Parent
local DailyRewardScreen = ShopGUI.Shop.Home.DailyReward
local CollectButton = DailyRewardScreen.Collect
local Time = DailyRewardScreen.Time
game.ReplicatedStorage.PresentDailyReward.OnClientEvent:Connect(function(Duration, Reward)
Time.Text = "Next reward in "..Duration.." hours"
CollectButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ClaimDailyReward:FireServer()
Time.Text = "Awarded "..Reward.." credits"
end)
end)