Is there anything I can add to this script to make it wait for the loading screen GUI be over?
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)
01 | local leaderstats = Instance.new( "Folder" ) |
02 | leaderstats.Name = "leaderstats" |
03 | leaderstats.Parent = player |
05 | local coins = Instance.new( "IntValue" ) |
07 | coins.Parent = leaderstats |
09 | local timeNow = os.time() |
14 | data = DataStore:GetAsync(player.UserId.. "-dailyReward" ) |
21 | local timeSinceLastClaim = timeNow - data |
23 | print ( "Time since last claim " ..timeSinceLastClaim) |
25 | if (timeSinceLastClaim / 3600 ) > = hourWait then |
27 | local reward = possibleRewards [ math.random( 1 ,#possibleRewards) ] |
28 | game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward) |
30 | connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect( function (triggeringPlayer) |
31 | if triggeringPlayer = = player then |
32 | print ( "Reward Claimed" ) |
33 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward |
34 | DataStore.SetAsync(player.UserId.. "-dailyReward" ,os.time()) |
35 | connection:Disconnect() |
39 | print ( "Player is uneligible right now" ) |
46 | local reward = possibleRewards [ math.random( 1 ,#possibleRewards) ] |
47 | game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward) |
49 | connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect( function (triggeringPlayer) |
50 | if triggeringPlayer = = player then |
51 | print ( "Reward Claimed" ) |
52 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward |
53 | DataStore.SetAsync(player.UserId.. "-dailyReward" ,os.time()) |
54 | connection:Disconnect() |
end)
game.Players.PlayerRemoving:Connect(function(player)
local data
pcall (function()
data = DataStore:GetAsync(player.UserId.."-dailyReward")
print("Getting the data")
end)
4 | local timeVal = os.time() |
5 | DataStore:SetAsync(player.UserId.. "-dailyReward" ) |
7 | print ( "Saved because your a new player" ) |
end)