Advertisement
Cakey3101

EP 10 - Daily Rewards Client

May 7th, 2025
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3.  
  4. local Remotes = ReplicatedStorage.Remotes
  5. local DailyRewardsConfig = require(ReplicatedStorage.Configs.DailyRewards)
  6. local TweenGuiModule = require(script.Parent.TweenGui)
  7. local FormatNumber = require(ReplicatedStorage.Libs.FormatNumber.Simple)
  8.  
  9. local Player = Players.LocalPlayer
  10. local PlayerGui = Player.PlayerGui
  11.  
  12. local Gui = PlayerGui:WaitForChild("DailyRewards")
  13. local Frame = Gui.Frame
  14.  
  15. local Exit = Frame.Exit
  16. local Open = PlayerGui:WaitForChild("Main").Right.DailyRewards
  17.  
  18. local Container = Frame.Container
  19.  
  20. local Template = Container.Template
  21.  
  22. local Days = {}
  23.  
  24. for Day in pairs(DailyRewardsConfig) do
  25.     table.insert(Days, Day)
  26. end
  27.  
  28. table.sort(Days, function(A, B)
  29.     return tonumber(A) < tonumber(B)
  30. end)
  31.  
  32. local function UpdateButtons()
  33.     local DailyRewardsStat = Player:FindFirstChild("DailyReward")
  34.     local LastCollectTime = Player:FindFirstChild("LastCollectTime")
  35.     if not DailyRewardsStat or not LastCollectTime then return end
  36.  
  37.     local CurrentDay = DailyRewardsStat.Value
  38.     local LastClaim = LastCollectTime.Value
  39.     local CurrentTime = os.time()
  40.  
  41.     for _, DailyRewardTemplate in ipairs(Container:GetChildren()) do
  42.         if DailyRewardTemplate:IsA("Frame") and tonumber(DailyRewardTemplate.Name) then
  43.             local Day = tonumber(DailyRewardTemplate.Name)
  44.             local ClaimButton = DailyRewardTemplate:FindFirstChild("ClaimReward")
  45.  
  46.             if not ClaimButton then continue end
  47.  
  48.             if Day < CurrentDay then
  49.                 ClaimButton.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
  50.                 ClaimButton.Label.Text = `Claimed!`
  51.                 ClaimButton.AutoButtonColor = false
  52.                 ClaimButton.Active = false
  53.             elseif Day == CurrentDay then
  54.                 local RemaningTime = (LastClaim + 24 * 60 * 60) - CurrentTime
  55.                 if RemaningTime > 0 then
  56.                     ClaimButton.BackgroundColor3 = Color3.fromRGB(70, 232, 70)
  57.                     ClaimButton.Label.Text = string.format("%02d:%02d:%02d", math.floor(RemaningTime / 3600), math.floor((RemaningTime % 3600) / 60), RemaningTime % 60)
  58.                     ClaimButton.AutoButtonColor = false
  59.                     ClaimButton.Active = false
  60.  
  61.                     task.spawn(function()
  62.                         while RemaningTime > 0 do
  63.                             task.wait(1)
  64.                             RemaningTime -= 1
  65.                             ClaimButton.Label.Text = string.format("%02d:%02d:%02d", math.floor(RemaningTime / 3600), math.floor((RemaningTime % 3600) / 60), RemaningTime % 60)
  66.                         end
  67.  
  68.                         UpdateButtons()
  69.                     end)
  70.                 end
  71.  
  72.                 ClaimButton.BackgroundColor3 = Color3.fromRGB(70, 232, 70)
  73.                 ClaimButton.Label.Text = `Claim!`
  74.                 ClaimButton.AutoButtonColor = true
  75.                 ClaimButton.Active = true
  76.             else
  77.                 ClaimButton.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
  78.                 ClaimButton.Label.Text = `Day {tostring(Day)}!`
  79.                 ClaimButton.AutoButtonColor = false
  80.                 ClaimButton.Active = false
  81.             end
  82.  
  83.             ClaimButton.MouseButton1Click:Connect(function()
  84.                 Remotes.ClaimDailyReward:FireServer(Day)
  85.             end)
  86.         end
  87.     end
  88. end
  89.  
  90. local function GenerateGui()
  91.     for _, Day in ipairs(Days) do
  92.         local Reward = DailyRewardsConfig[Day]
  93.  
  94.         local DailyRewardTemplate = Template:Clone()
  95.         DailyRewardTemplate.Parent = Container
  96.         DailyRewardTemplate.Name = Day
  97.         DailyRewardTemplate.Visible = true
  98.  
  99.         DailyRewardTemplate.RewardType.Text = Reward.Type
  100.         DailyRewardTemplate.RewardAmount.Text = `+{tostring(FormatNumber.Format(Reward.Amount))}`
  101.  
  102.         if Reward.Type == "Rings" then
  103.             DailyRewardTemplate.Icon.Image = "rbxassetid://136483881101942"
  104.         end
  105.     end
  106.  
  107.     UpdateButtons()
  108. end
  109.  
  110. GenerateGui()
  111.  
  112. Player:WaitForChild("DailyReward").Changed:Connect(UpdateButtons)
  113. Remotes.ClaimDailyReward.OnClientEvent:Connect(UpdateButtons)
  114.  
  115. Open.MouseButton1Click:Connect(function()
  116.     if Gui.Enabled == true then
  117.         TweenGuiModule.CloseGui(Gui, Frame)
  118.     else
  119.         TweenGuiModule.OpenGui(Gui, Frame)
  120.     end
  121. end)
  122.  
  123. Exit.MouseButton1Click:Connect(function()
  124.     TweenGuiModule.CloseGui(Gui, Frame)
  125. end)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement