Advertisement
qsenko1

Gamepass Touch Giver Working!!

Sep 10th, 2021
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. local Players = game.Players
  2. local MarkeplaceService = game:GetService("MarketplaceService")
  3. local ItemGivers = game.Workspace.CoilsModel.Model -- the model with all the touchpads
  4. local ItemLocation = game.ReplicatedStorage.GamepassItems -- the location of the tools in replicate storage
  5. local Items = {"GravityCoil","AccelerationCoil","BoomBox","FlyingCarpet","FlyingCloud"} -- a random table test
  6.  
  7. local debounce = true
  8.  
  9. for i,v in pairs(ItemGivers:GetDescendants()) do   
  10.     --print(v)
  11.     if v:IsA("Part") and v.Name == "Giver" then
  12.         print(v)
  13.         v.Touched:Connect(function(hit)            
  14.             local player = Players:GetPlayerFromCharacter(hit.Parent)
  15.             if player and debounce then
  16.                 debounce = false
  17.                 local GamepassId = v.Gamepass.Value -- an int value that is taken from the part thats touched
  18.                 local GamepassName = v.ItemName.Value -- a string value that is taken from the part thats touched
  19.                 local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassId)
  20.                 print(player)
  21.                 print(GamepassId)
  22.                 print(GamepassName)
  23.                 print(ownsGamepass)
  24.                
  25.                 if not ownsGamepass then
  26.                     local Purchase = game:GetService("MarketplaceService"):PromptGamePassPurchase(player,GamepassId)
  27.                     --print(Purchase)
  28.                     local function gamepassPurchaseFinished(player,GamepassId,wasPurchased)
  29.                         --Market:Disconnect()
  30.                         if wasPurchased == true and debounce then
  31.                             debounce = false
  32.                             local items1 = ItemLocation:FindFirstChild(GamepassName):Clone()
  33.                             items1.Parent = player.Backpack
  34.                             local items2 = ItemLocation:FindFirstChild(GamepassName):Clone()
  35.                             items2.Parent = player.StarterGear
  36.                             wait(1)
  37.                             debounce = true
  38.                             return
  39.                         else       
  40.                             print("Canceled")
  41.                             return
  42.                         end
  43.                     end
  44.                
  45.                     MarkeplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
  46.                    
  47.                 end
  48.  
  49.                 if ownsGamepass then
  50.                     print("owned")
  51.                    
  52.                     if player.Backpack:FindFirstChild(GamepassName) then
  53.                     player.Backpack:FindFirstChild(GamepassName):Destroy()
  54.                     player.StarterGear:FindFirstChild(GamepassName):Destroy()
  55.                         print("hi")
  56.                     else
  57.                         print("item not found")
  58.                         local item1 = ItemLocation:FindFirstChild(GamepassName):Clone()
  59.                         item1.Parent = player.Backpack
  60.                         local item2 = ItemLocation:FindFirstChild(GamepassName):Clone()
  61.                         item2.Parent = player.StarterGear
  62.                     --[[for i,items in pairs(player.Backpack:GetChildren(),player.StarterGear:GetChildren()) do
  63.                         print(items.Name)
  64.                         print(GamepassName ~= items)
  65.                         print(GamepassName == items)
  66.                         print(GamepassName == player.Backpack:FindFirstChild(items.Name))
  67.                         print(GamepassName == player.Backpack:FindFirstChild(items))
  68.                         print(GamepassName ~= player.Backpack:FindFirstChild(items.Name))
  69.                         print(GamepassName ~= player.Backpack:FindFirstChild(items))
  70.                         print(player.Backpack:FindFirstChild(GamepassName))
  71.                         if items:IsA("Tool") and GamepassName ~= items then
  72.                             print(GamepassName)
  73.                             print(items)                                       
  74.                         if GamepassName ~= player.Backpack:FindFirstChild(items.Name) then
  75.                                 --  print(items2)
  76.                                 items:Destroy()        
  77.                                 player.StarterGear:FindFirstChild(items.Name):Destroy()
  78.                               break
  79.                            end
  80.                         end
  81.                        
  82.                         if GamepassName ~= items.Name then -- GamepassName ~= items.Name or
  83.                             print("hi")
  84.                         --  items = GamepassName
  85.                             print(items)
  86.                             for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
  87.                                 if itemsinstorage:IsA("Tool") and itemsinstorage.Name ~= items.Name then
  88.                                     print(itemsinstorage)
  89.                                     local item1 = itemsinstorage:Clone()
  90.                                     local item2 = itemsinstorage:Clone()
  91.                                     item1.Parent = player.Backpack
  92.                                     item2.Parent = player.StarterGear
  93.                                     break
  94.                                 end
  95.                             end
  96.                             debounce = true
  97.                         end --]]
  98.                     --[[elseif player.Backpack:FindFirstChild(Items) ~= GamepassName then
  99.                             print("hi")
  100.                             for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
  101.                                 print(itemsinstorage)
  102.                                 itemsinstorage = GamepassName
  103.                                 print(itemsinstorage)
  104.                                
  105.                                 if itemsinstorage == GamepassName then
  106.                                     print(itemsinstorage)
  107.                                     local item1 = itemsinstorage:Clone()
  108.                                     item1.Parent = player.Backpack
  109.                                 end
  110.                                 break
  111.                             end
  112.                             break  
  113.                         end
  114.  
  115.                 --[[    if Items ~= GamepassName then
  116.                         print(GamepassName)
  117.                         print(items.Name)
  118.                         local item1 = ItemLocation:FindFirstChild("GamepassName"):Clone()
  119.                         item1.Parent = player.Backpack
  120.                         local item2 = items:Clone()
  121.                         item2.Parent = player.StarterGear
  122.                     end --]]
  123.                 --      break
  124.                     end
  125.                 end
  126.  
  127.                 wait(1)
  128.                 debounce = true
  129.             end
  130.         end)
  131.     end
  132. end
  133.  
  134. --Market = MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement