Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game.Players
- local MarkeplaceService = game:GetService("MarketplaceService")
- local ItemGivers = game.Workspace.CoilsModel.Model -- the model with all the touchpads
- local ItemLocation = game.ReplicatedStorage.GamepassItems -- the location of the tools in replicate storage
- local Items = {"GravityCoil","AccelerationCoil","BoomBox","FlyingCarpet","FlyingCloud"} -- a random table test
- local debounce = true
- for i,v in pairs(ItemGivers:GetDescendants()) do
- --print(v)
- if v:IsA("Part") and v.Name == "Giver" then
- print(v)
- v.Touched:Connect(function(hit)
- local player = Players:GetPlayerFromCharacter(hit.Parent)
- if player and debounce then
- debounce = false
- local GamepassId = v.Gamepass.Value -- an int value that is taken from the part thats touched
- local GamepassName = v.ItemName.Value -- a string value that is taken from the part thats touched
- local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassId)
- print(player)
- print(GamepassId)
- print(GamepassName)
- print(ownsGamepass)
- if not ownsGamepass then
- local Purchase = game:GetService("MarketplaceService"):PromptGamePassPurchase(player,GamepassId)
- --print(Purchase)
- local function gamepassPurchaseFinished(player,GamepassId,wasPurchased)
- --Market:Disconnect()
- if wasPurchased == true and debounce then
- debounce = false
- local items1 = ItemLocation:FindFirstChild(GamepassName):Clone()
- items1.Parent = player.Backpack
- local items2 = ItemLocation:FindFirstChild(GamepassName):Clone()
- items2.Parent = player.StarterGear
- wait(1)
- debounce = true
- return
- else
- print("Canceled")
- return
- end
- end
- MarkeplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
- end
- if ownsGamepass then
- print("owned")
- if player.Backpack:FindFirstChild(GamepassName) then
- player.Backpack:FindFirstChild(GamepassName):Destroy()
- player.StarterGear:FindFirstChild(GamepassName):Destroy()
- print("hi")
- else
- print("item not found")
- local item1 = ItemLocation:FindFirstChild(GamepassName):Clone()
- item1.Parent = player.Backpack
- local item2 = ItemLocation:FindFirstChild(GamepassName):Clone()
- item2.Parent = player.StarterGear
- --[[for i,items in pairs(player.Backpack:GetChildren(),player.StarterGear:GetChildren()) do
- print(items.Name)
- print(GamepassName ~= items)
- print(GamepassName == items)
- print(GamepassName == player.Backpack:FindFirstChild(items.Name))
- print(GamepassName == player.Backpack:FindFirstChild(items))
- print(GamepassName ~= player.Backpack:FindFirstChild(items.Name))
- print(GamepassName ~= player.Backpack:FindFirstChild(items))
- print(player.Backpack:FindFirstChild(GamepassName))
- if items:IsA("Tool") and GamepassName ~= items then
- print(GamepassName)
- print(items)
- if GamepassName ~= player.Backpack:FindFirstChild(items.Name) then
- -- print(items2)
- items:Destroy()
- player.StarterGear:FindFirstChild(items.Name):Destroy()
- break
- end
- end
- if GamepassName ~= items.Name then -- GamepassName ~= items.Name or
- print("hi")
- -- items = GamepassName
- print(items)
- for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
- if itemsinstorage:IsA("Tool") and itemsinstorage.Name ~= items.Name then
- print(itemsinstorage)
- local item1 = itemsinstorage:Clone()
- local item2 = itemsinstorage:Clone()
- item1.Parent = player.Backpack
- item2.Parent = player.StarterGear
- break
- end
- end
- debounce = true
- end --]]
- --[[elseif player.Backpack:FindFirstChild(Items) ~= GamepassName then
- print("hi")
- for i,itemsinstorage in pairs(ItemLocation:GetChildren()) do
- print(itemsinstorage)
- itemsinstorage = GamepassName
- print(itemsinstorage)
- if itemsinstorage == GamepassName then
- print(itemsinstorage)
- local item1 = itemsinstorage:Clone()
- item1.Parent = player.Backpack
- end
- break
- end
- break
- end
- --[[ if Items ~= GamepassName then
- print(GamepassName)
- print(items.Name)
- local item1 = ItemLocation:FindFirstChild("GamepassName"):Clone()
- item1.Parent = player.Backpack
- local item2 = items:Clone()
- item2.Parent = player.StarterGear
- end --]]
- -- break
- end
- end
- wait(1)
- debounce = true
- end
- end)
- end
- end
- --Market = MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement