Advertisement
Sungmingamerpro13

Extra Life With Tool (ProcessReceiptScript)

Nov 24th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.66 KB | None | 0 0
  1. -- This code should be in a 'Script' object within 'ServerScriptService'
  2. local MarketplaceService = game:GetService("MarketplaceService")
  3. local boughtLifeEvent = game.ReplicatedStorage.DiedEvents.boughtLifeEvent
  4. local reviveEvent2 = game.ReplicatedStorage.DiedEvents.reviveEvent2
  5. local reviveEvent3 = game.ReplicatedStorage.DiedEvents.reviveEvent3
  6.  
  7. local RoleItems = game.ServerStorage.RoleItems
  8.  
  9. local function processReceipt(receiptInfo)
  10.     -- Find the player who made the purchase in the server
  11.     local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
  12.     if player then
  13.         -- Output what product they bought
  14.         print(player.Name .. " just bought " .. receiptInfo.ProductId)
  15.         boughtLifeEvent:FireClient(player)
  16.        
  17.        
  18.         -- IMPORTANT: Tell Roblox that the game successfully handled the purchase
  19.         return Enum.ProductPurchaseDecision.PurchaseGranted
  20.     end
  21. end
  22.  
  23. -- Set the callback (this can only be done once by one script on the server!)
  24. MarketplaceService.ProcessReceipt = processReceipt
  25.  
  26. reviveEvent2.OnServerEvent:Connect(function(player)
  27.     player:LoadCharacter()
  28.     if (player) and (player.Backpack) then
  29.         for _, Item in pairs(player.Backpack:GetChildren()) do
  30.             if Item:IsA("Tool") then
  31.                 Item:Destroy()
  32.             end
  33.         end
  34.     end
  35.     RoleItems.Bat:Clone().Parent = player.Backpack
  36.     RoleItems.Medkit:Clone().Parent = player.Backpack
  37. end)
  38.  
  39. reviveEvent3.OnServerEvent:Connect(function(player)
  40.     player:LoadCharacter()
  41.     if (player) and (player.Backpack) then
  42.         for _, Item in pairs(player.Backpack:GetChildren()) do
  43.             if Item:IsA("Tool") then
  44.                 Item:Destroy()
  45.             end
  46.         end
  47.     end
  48.     RoleItems.Bat:Clone().Parent = player.Backpack
  49. end)
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement