qsenko1

Multiple Gamepass Shop Handler!!

Jul 20th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. local MarkeplaceService = game:GetService("MarketplaceService")
  2. local AccessoriesEvent = game.ReplicatedStorage:WaitForChild("Remotes").AccessoriesEvent
  3. local PurchaseNotify = game.ReplicatedStorage:WaitForChild("Remotes").PurchaseNotify
  4. local DisconnectValue
  5. local ItemLocation = game.ReplicatedStorage.GamepassItems
  6. local debounce = true
  7.  
  8. AccessoriesEvent.OnServerEvent:Connect(function(Player,Name,Price,GamepassId)
  9.     print(Player,Name,Price,GamepassId)
  10.     local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,GamepassId)
  11.    
  12.     if not ownsGamepass then
  13.         local Purchase = game:GetService("MarketplaceService"):PromptGamePassPurchase(Player,GamepassId)
  14.         --print(Purchase)
  15.         local function gamepassPurchaseFinished(player,GamepassId,wasPurchased)
  16.           --print("gamepasses activated")
  17.             if wasPurchased == true and debounce then
  18.                 debounce = false
  19.                 Player.Character:FindFirstChild("Humanoid"):UnequipTools()
  20.                 local items1 = ItemLocation:FindFirstChild(Name):Clone()
  21.                 items1.Parent = player.Backpack
  22.                 local items2 = ItemLocation:FindFirstChild(Name):Clone()
  23.                 items2.Parent = player.StarterGear     
  24.                 AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
  25.                 local NewName = Name
  26.                 print(NewName)
  27.                 local NewPrice = Price
  28.                 print(NewPrice)
  29.                 local PlayerName = Player.Name
  30.                 PurchaseNotify:FireAllClients(player.Name,Price,Name)--PlayerName,NewName
  31.                 task.wait(1)
  32.                 DisconnectValue:Disconnect()
  33.                 debounce = true
  34.                 return
  35.             else       
  36.                 --  print("Canceled") -- noticed that the else runs a few times but thats not causing any problems
  37.                 return
  38.             end
  39.         end
  40.  
  41.         DisconnectValue = MarkeplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
  42.     end
  43.    
  44.     if ownsGamepass then
  45.         Player.Character:FindFirstChild("Humanoid"):UnequipTools()
  46.         if Player.Backpack:FindFirstChild(Name) then
  47.             Player.Backpack:FindFirstChild(Name):Destroy()
  48.             Player.StarterGear:FindFirstChild(Name):Destroy()
  49.             AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
  50.         else
  51.             local item1 = ItemLocation:FindFirstChild(Name):Clone()
  52.             item1.Parent = Player.Backpack
  53.             local item2 = ItemLocation:FindFirstChild(Name):Clone()
  54.             item2.Parent = Player.StarterGear
  55.             AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
  56.         end
  57.     end
  58. end)
Add Comment
Please, Sign In to add comment