Advertisement
Guest User

Badge Giver

a guest
Jul 18th, 2022
1,000
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 1
  1. local BadgeService = game:GetService("BadgeService") or game:FindService("BadgeService")
  2. local Players = game:GetService("Players") or game:FindService("Players")
  3.  
  4. local BadgeID1 = 123456789
  5. local BadgeID2 = 987654321
  6. local BadgeID3 = 696969696
  7.  
  8. Players.PlayerAdded:Connect(function(plr)
  9.     repeat task.wait() until plr:FindFirstChild("leaderstats") ~= nil
  10.     local leaderstats = plr.leaderstats
  11.     local hoursValue = leaderstats["Time Played"]
  12.  
  13.     hoursValue:GetPropertyChangedSignal("Value"):Connect(function()
  14.         local result
  15.  
  16.         local a, b = pcall(function()
  17.             result = BadgeService:UserHasBadgeAsync(plr.UserId, BadgeID1)
  18.         end)
  19.        
  20.         local c, d = pcall(function()
  21.             result = BadgeService:UserHasBadgeAsync(plr.UserId, BadgeID2)
  22.         end)
  23.        
  24.         local e, f = pcall(function()
  25.             result = BadgeService:UserHasBadgeAsync(plr.UserId, BadgeID3)
  26.         end)
  27.  
  28.         if not b then
  29.             warn("An error occured while checking player awards, more: "..b)
  30.             return
  31.         end
  32.        
  33.         if not b then
  34.             warn("An error occured while checking player awards, more: "..d)
  35.             return
  36.         end
  37.        
  38.         if not b then
  39.             warn("An error occured while checking player awards, more: "..f)
  40.             return
  41.         end
  42.  
  43.         if hoursValue.Value >= 0.08 and not result then --Change the Value
  44.             local awardBadgeResult
  45.  
  46.             local s2, e2 = pcall(function()
  47.                 awardBadgeResult = BadgeService:AwardBadge(plr.UserId, BadgeID1)
  48.             end)
  49.  
  50.             if s2 and awardBadgeResult then
  51.                 print("Badge was awarded successfully to the player named: "..plr.Name)
  52.             end
  53.         end
  54.        
  55.         if hoursValue.Value >= 0.08 and not result then --Change the Value
  56.             local awardBadgeResult
  57.  
  58.             local s2, e2 = pcall(function()
  59.                 awardBadgeResult = BadgeService:AwardBadge(plr.UserId, BadgeID2)
  60.             end)
  61.  
  62.             if s2 and awardBadgeResult then
  63.                 print("Badge was awarded successfully to the player named: "..plr.Name)
  64.             end
  65.         end
  66.        
  67.         if hoursValue.Value >= 0.08 and not result then --Change the Value
  68.             local awardBadgeResult
  69.  
  70.             local s2, e2 = pcall(function()
  71.                 awardBadgeResult = BadgeService:AwardBadge(plr.UserId, BadgeID3)
  72.             end)
  73.  
  74.             if s2 and awardBadgeResult then
  75.                 print("Badge was awarded successfully to the player named: "..plr.Name)
  76.             end
  77.         end
  78.        
  79.     end)
  80. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement