Advertisement
Cakey3101

Daily Rewards Server Script

Apr 26th, 2025
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | Source Code | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2.  
  3. local Remotes = ReplicatedStorage.Remotes
  4. local DailyRewardsConfig = require(ReplicatedStorage.DailyRewards)
  5.  
  6. local function ClaimReward(Player: Player, Day: number)
  7.     local DailyRewardStat = Player:FindFirstChild("DailyReward")
  8.     local LastCollectTimeStat = Player:FindFirstChild("LastCollectTime")
  9.     local Leaderstats = Player:FindFirstChild("leaderstats")
  10.    
  11.     local CurrentDay = DailyRewardStat.Value
  12.     local LastCollectTime = LastCollectTimeStat.Value
  13.     local CurrentTime = os.time()
  14.    
  15.     if CurrentDay ~= Day then return end
  16.     if LastCollectTime ~= 0 and CurrentTime - LastCollectTime < 24 * 60 * 60 then return end
  17.    
  18.     local Reward = DailyRewardsConfig[tostring(Day)]
  19.     if not Reward then return end
  20.    
  21.     local RewardStat = Leaderstats:FindFirstChild(Reward.Type)
  22.     if RewardStat and RewardStat:IsA("NumberValue") then
  23.         RewardStat.Value += Reward.Amount
  24.         print("Reward Claimed!")
  25.     end
  26.    
  27.     LastCollectTimeStat.Value = CurrentTime
  28.     DailyRewardStat.Value = CurrentDay + 1
  29.    
  30.     Remotes.ClaimDailyReward:FireClient(Player)
  31. end
  32.  
  33. Remotes.ClaimDailyReward.OnServerEvent:Connect(ClaimReward)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement