denissini15

Untitled

Jan 25th, 2021
902
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mrk = game:GetService("MarketplaceService")
  2. local badge = game:GetService("BadgeService")
  3. local plrs = game:GetService("Players")
  4.  
  5. local plrs = game:GetService("Players")
  6. _G.marketcache = _G.marketcache or {
  7.     gamepasses = {};
  8.     badges = {};
  9. }
  10.  
  11. local checkfor = {}
  12. local cache = _G.marketcache
  13. local mod = {}
  14.  
  15.  
  16. mod.PromptGamePassPurchase = function(self, player, gamepass)
  17.     mrk:PromptGamePassPurchase(player, gamepass, 2)
  18. end
  19.  
  20. mod.PromptGamePassPurchaseFinished = mrk.PromptGamePassPurchaseFinished
  21.  
  22. mod.AwardBadge = function(self, userid, badgeid)
  23.     cache.badges[badgeid] = cache.badges[badgeid] or {}
  24.     if not cache.badges[badgeid][userid] then
  25.         cache.badges[badgeid][userid] = true
  26.         badge:AwardBadge(userid, badgeid)
  27.         return "Awarded"
  28.     else
  29.         return "Already awarded"
  30.     end
  31. end
  32.  
  33. mod.SetBadgeCheckList = function(self, ...)
  34.     for _, id in pairs({...}) do
  35.         checkfor[id] = true
  36.     end
  37. end
  38.  
  39.  
  40. mrk.PromptGamePassPurchaseFinished:Connect(function(player, gamepassid, waspurchased )
  41.     if player and waspurchased then
  42.         cache.gamepasses[gamepassid] = cache.gamepasses[gamepassid] or {}
  43.         cache.gamepasses[gamepassid][player.UserId] = true
  44.     end
  45. end)
  46.  
  47.  
  48.  
  49. mod.Gamepass = function(userid, gamepassid)
  50.     if cache.gamepasses[gamepassid] and cache.gamepasses[gamepassid][userid] then
  51.         return cache.gamepasses[gamepassid][userid]
  52.     else
  53.         local result
  54.         pcall(function()
  55.             result = mrk:UserOwnsGamePassAsync(userid, gamepassid)
  56.             cache.gamepasses[gamepassid] = {}
  57.             cache.gamepasses[gamepassid][userid] = result
  58.         end)
  59.         return result
  60.     end
  61. end
  62.  
  63. function mod:UserOwnsGamePassAsync(userid, gamepassid)
  64.     return mod.Gamepass(userid, gamepassid)
  65. end
  66.  
  67.  
  68.  
  69. local isServer = not game:GetService("Players").LocalPlayer
  70.  
  71. local on_player_join = function(plr)
  72.     if isServer then
  73.         for id, _ in pairs(checkfor) do
  74.             local cor = coroutine.create(function()
  75.                 cache.badges[id]= cache.badges[id] or {}
  76.                
  77.                 cache.badges[id]
  78.                     [plr.UserId] = badge:UserHasBadgeAsync(plr.UserId, id)
  79.                
  80.             end)
  81.             coroutine.resume(cor)
  82.         end
  83.     end
  84. end
  85.  
  86.  
  87. for _, plr in pairs(plrs:GetPlayers()) do
  88.     on_player_join(plr)
  89. end
  90.  
  91. plrs.PlayerAdded:Connect(on_player_join)
  92.  
  93. return mod
RAW Paste Data