Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MarkeplaceService = game:GetService("MarketplaceService")
- local AccessoriesEvent = game.ReplicatedStorage:WaitForChild("Remotes").AccessoriesEvent
- local PurchaseNotify = game.ReplicatedStorage:WaitForChild("Remotes").PurchaseNotify
- local DisconnectValue
- local ItemLocation = game.ReplicatedStorage.GamepassItems
- local debounce = true
- AccessoriesEvent.OnServerEvent:Connect(function(Player,Name,Price,GamepassId)
- print(Player,Name,Price,GamepassId)
- local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,GamepassId)
- if not ownsGamepass then
- local Purchase = game:GetService("MarketplaceService"):PromptGamePassPurchase(Player,GamepassId)
- --print(Purchase)
- local function gamepassPurchaseFinished(player,GamepassId,wasPurchased)
- --print("gamepasses activated")
- if wasPurchased == true and debounce then
- debounce = false
- Player.Character:FindFirstChild("Humanoid"):UnequipTools()
- local items1 = ItemLocation:FindFirstChild(Name):Clone()
- items1.Parent = player.Backpack
- local items2 = ItemLocation:FindFirstChild(Name):Clone()
- items2.Parent = player.StarterGear
- AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
- local NewName = Name
- print(NewName)
- local NewPrice = Price
- print(NewPrice)
- local PlayerName = Player.Name
- PurchaseNotify:FireAllClients(player.Name,Price,Name)--PlayerName,NewName
- task.wait(1)
- DisconnectValue:Disconnect()
- debounce = true
- return
- else
- -- print("Canceled") -- noticed that the else runs a few times but thats not causing any problems
- return
- end
- end
- DisconnectValue = MarkeplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
- end
- if ownsGamepass then
- Player.Character:FindFirstChild("Humanoid"):UnequipTools()
- if Player.Backpack:FindFirstChild(Name) then
- Player.Backpack:FindFirstChild(Name):Destroy()
- Player.StarterGear:FindFirstChild(Name):Destroy()
- AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
- else
- local item1 = ItemLocation:FindFirstChild(Name):Clone()
- item1.Parent = Player.Backpack
- local item2 = ItemLocation:FindFirstChild(Name):Clone()
- item2.Parent = Player.StarterGear
- AccessoriesEvent:FireClient(Player,Name,Price,GamepassId)
- end
- end
- end)
Add Comment
Please, Sign In to add comment