I have a loading screen and this GUI loads in at the same time and looks cluttered.. The Script:
local DataStore = game:GetService("DataStoreService"):GetDataStore ("DailyRewards")
local hourWait = 24
local possibleRewards = {10,15,10,10,10,5,5,5,5,5,5,5,5,5,5,5,10,10,10,10,10,10,15,15,15,750}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Parent = leaderstats local timeNow = os.time() local data pcall(function() data = DataStore:GetAsync(player.UserId.."-dailyReward") print("Getting Data") end) if data ~= nil then -- Returning player to the game local timeSinceLastClaim = timeNow - data -- Number in sec since the last reward was claimed print ("Time since last claim "..timeSinceLastClaim) if (timeSinceLastClaim / 3600) >= hourWait then -- They are eligible for a reward local reward = possibleRewards[math.random(1,#possibleRewards)] game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward) local connection connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer) if triggeringPlayer == player then print ("Reward Claimed") player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward DataStore.SetAsync(player.UserId.."-dailyReward",os.time()) connection:Disconnect() end end) else print ("Player is uneligible right now") end else -- New player print ("New player") local reward = possibleRewards[math.random(1,#possibleRewards)] game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward) local connection connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer) if triggeringPlayer == player then print ("Reward Claimed") player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward DataStore.SetAsync(player.UserId.."-dailyReward",os.time()) connection:Disconnect() end end) end
end)
game.Players.PlayerRemoving:Connect(function(player) local data pcall (function() data = DataStore:GetAsync(player.UserId.."-dailyReward") print("Getting the data") end)
if data == nil then -- New player pcall(function() local timeVal = os.time() DataStore:SetAsync(player.UserId.."-dailyReward") end) print ("Saved because your a new player") end
end)