Advertisement
qsenko1

Gamepass giver small system thing

Sep 10th, 2021
1,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 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.                 end
  29.  
  30.                 if ownsGamepass then
  31.                     print("owned")
  32.                     for i,items in pairs(player.Backpack:GetChildren()) do
  33.                         print(items.Name)
  34.                         if GamepassName == player.Backpack:FindFirstChild(items.Name) then
  35.                             print(GamepassName)
  36.                             print(items)               
  37.                            
  38.                             for i,items2 in pairs(player.StarterGear:GetChildren()) do
  39.                                
  40.                                 if GamepassName == player.Backpack:FindFirstChild(items.Name) then
  41.                                     print(items2)
  42.                                     items:Destroy()
  43.                                     items2:Destroy()
  44.                                     break
  45.                                 end
  46.                             end
  47.                             break
  48.                         end
  49.                        
  50.                         if GamepassName ~= player.Backpack:FindFirstChild(items.Name) then -- GamepassName ~= items.Name or
  51.                             print("hi")
  52.                         --  items = GamepassName
  53.                             print(items)
  54.                             for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
  55.                                 if itemsinstorage:IsA("Tool") and itemsinstorage.Name ~= items.Name then
  56.                                     print(itemsinstorage)
  57.                                     local item1 = itemsinstorage:Clone()
  58.                                     item1.Parent = player.Backpack
  59.                                     local item2 = itemsinstorage:Clone()
  60.                                     item2.Parent = player.StarterGear
  61.                                     break
  62.                                 end
  63.                             end
  64.                             debounce = true
  65.                         end
  66.                     --[[elseif player.Backpack:FindFirstChild(Items) ~= GamepassName then
  67.                             print("hi")
  68.                             for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
  69.                                 print(itemsinstorage)
  70.                                 itemsinstorage = GamepassName
  71.                                 print(itemsinstorage)
  72.                                
  73.                                 if itemsinstorage == GamepassName then
  74.                                     print(itemsinstorage)
  75.                                     local item1 = itemsinstorage:Clone()
  76.                                     item1.Parent = player.Backpack
  77.                                 end
  78.                                 break
  79.                             end
  80.                             break  
  81.                         end
  82.  
  83.                 --[[    if Items ~= GamepassName then
  84.                         print(GamepassName)
  85.                         print(items.Name)
  86.                         local item1 = ItemLocation:FindFirstChild("GamepassName"):Clone()
  87.                         item1.Parent = player.Backpack
  88.                         local item2 = items:Clone()
  89.                         item2.Parent = player.StarterGear
  90.                     end --]]
  91.                 --      break
  92.                     end
  93.                 end
  94.  
  95.                 wait(1)
  96.                 debounce = true
  97.             end
  98.         end)
  99.     end
  100. end
  101.  
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement