How could this be more efficient? This is suppose wait after a certain time and then award the player, and also show the time left until the player will be awarded. How could this be more efficient because it does not loop the way It should. Thanks!
DataStore = Game:GetService("DataStoreService"):GetDataStore("Reward") Amount = 120 Game.Players.PlayerAdded:connect(function(Player) repeat wait(1) until Player:FindFirstChild("CashPLAYER") repeat wait(1) until Player:FindFirstChild("LevelPLAYER") local CashPLAYER = Player:FindFirstChild("CashPLAYER"); local LevelPLAYER = Player:FindFirstChild("LevelPLAYER"); local PlayerGui = Player:WaitForChild("PlayerGui"):WaitForChild("Menu"); local TextLabel = PlayerGui.TextLabel5 local Timer = PlayerGui.Level.TextLabel3 mod = Instance.new("BoolValue", Player) mod.Name = "Award" mod.Value = false while true do wait() if DataStore:GetAsync(Player.Name) then Orginal = DataStore:GetAsync(Player.Name) time = math.floor(tick()) if time-Orginal > Amount then CashPLAYER.Value = CashPLAYER.Value + 75 TextLabel.Visible = true Player.Award.Value = true wait(3) TextLabel.Visible = false end else time = tick() DataStore:SetAsync(Player.Name, time) CashPLAYER.Value = CashPLAYER.Value + 75 TextLabel.Visible = true Player.Award.Value = true wait(3) TextLabel.Visible = false end Seconds = Amount-(time-Orginal) Minutes = Seconds/60 Timer.Text = "Next award: "..math.ceil(Minutes) end end) Game.Players.PlayerRemoving:connect(function(Player) if Player.Award.Value == true then time = math.floor(tick()) DataStore:SetAsync(Player.Name, time) end end)