Advertisement
TheBrainy06Alt

CustomVIP

Oct 12th, 2021
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local HttpService = game:GetService("HttpService")
  3. local TeleportService = game:GetService("TeleportService")
  4. local MarketplaceService = game:GetService("MarketplaceService")
  5. local Players = game:GetService("Players")
  6.  
  7. local vipStore = DataStoreService:GetDataStore("VipServerData")
  8. local serverCodeFormat = "%s-%s"
  9. local config = require(script.Config)
  10.  
  11. local vip = {}
  12.  
  13. local function HandlePurchase(receiptInfo)
  14.     local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
  15.  
  16.     if not plr then
  17.         return Enum.ProductPurchaseDecision.NotProcessedYet
  18.     end
  19.  
  20.     if plr then
  21.         local success = vip.CreateServer(plr)
  22.  
  23.         if success then
  24.             return Enum.ProductPurchaseDecision.PurchaseGranted
  25.         else
  26.             return Enum.ProductPurchaseDecision.NotProcessedYet
  27.         end
  28.     end
  29. end
  30.  
  31. MarketplaceService.ProcessReceipt = HandlePurchase
  32.  
  33. function vip.PromptPurchase(plr)
  34.     MarketplaceService:PromptProductPurchase(plr,config.ProductId)
  35. end
  36.  
  37. function vip.CreateServer(plr)
  38.     local vipData
  39.    
  40.     local success,res = pcall(function()
  41.         vipData = vipStore:GetAsync(plr.UserId)
  42.        
  43.         if vipData then
  44.             warn("Player already has a VIP server!")
  45.             return nil
  46.         else
  47.             vipData = {
  48.                 Owner = plr.UserId,
  49.                 TeleportCode = TeleportService:ReserveServer(game.PlaceId),
  50.                 ServerCode = serverCodeFormat:format(plr.UserId,HttpService:GenerateGUID(false):sub(1,5)),
  51.                 ExpiryDate = os.time() + (config.Validity * 86400)
  52.             }
  53.            
  54.         end
  55.        
  56.         vipStore:SetAsync(plr.UserId,vipData)
  57.     end)
  58.    
  59.     if success then
  60.         return vipData
  61.     else
  62.         warn(res)
  63.         return nil
  64.     end
  65. end
  66.  
  67. function vip.GetServerInfo(plr)
  68.     local serverData
  69.  
  70.     local success,res = pcall(function()
  71.         serverData = vipStore:GetAsync(plr.UserId)
  72.        
  73.         if not serverData then return warn("Server doesn't exist!") end
  74.     end)
  75.  
  76.     if not success then
  77.         warn(res)
  78.     else
  79.         return serverData
  80.     end
  81. end
  82.  
  83. function vip.TeleportToServer(plr,serverCode)
  84.     local serverData
  85.     local userId = serverCode:split("-")[1]
  86.    
  87.     local success,res = pcall(function()
  88.         serverData = vipStore:GetAsync(tonumber(userId))
  89.        
  90.         if not serverData then return warn("Server doesn't exist!") end
  91.        
  92.         if os.time() - serverData.ExpiryDate >= 0 then
  93.             serverData = nil
  94.            
  95.             vipStore:RemoveAsync(tonumber(userId))
  96.            
  97.             return warn("VIP server expired!")
  98.         end
  99.        
  100.         if serverData and serverData.ServerCode == serverCode then
  101.             TeleportService:TeleportToPrivateServer(game.PlaceId,serverData.TeleportCode,{plr})
  102.         end
  103.     end)
  104.    
  105.     if not success then
  106.         warn(res)
  107.     end
  108. end
  109.  
  110. return vip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement