Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("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 debounce = true
- local disconnectvalue
- for i,v in pairs(ItemGivers:GetDescendants()) do
- if v:IsA("Part") and v.Name == "Giver" then
- 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)
- if not ownsGamepass then
- local Purchase = game:GetService("MarketplaceService"):PromptGamePassPurchase(player,GamepassId)
- local function gamepassPurchaseFinished(player,GamepassId,wasPurchased)
- 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
- task.wait(1)
- disconnectvalue:Disconnect()
- debounce = true
- return
- else
- return
- end
- end
- disconnectvalue = MarkeplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
- end
- if ownsGamepass then
- if player.Backpack:FindFirstChild(GamepassName) then
- player.Backpack:FindFirstChild(GamepassName):Destroy()
- player.StarterGear:FindFirstChild(GamepassName):Destroy()
- else
- local item1 = ItemLocation:FindFirstChild(GamepassName):Clone()
- item1.Parent = player.Backpack
- local item2 = ItemLocation:FindFirstChild(GamepassName):Clone()
- item2.Parent = player.StarterGear
- end
- end
- task.wait(1)
- debounce = true
- end
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement