Advertisement
HowToRoblox

PurchaseHandler

Mar 4th, 2021
10,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local items = game.ReplicatedStorage:WaitForChild("Items")
  2.  
  3.  
  4. game.Players.PlayerAdded:Connect(function(plr)
  5.    
  6.    
  7.     local ls = Instance.new("Folder")
  8.     ls.Name = "leaderstats"
  9.     ls.Parent = plr
  10.    
  11.     local cash = Instance.new("IntValue")
  12.     cash.Name = "Cash"
  13.     cash.Value = 1000
  14.     cash.Parent = ls
  15. end)
  16.  
  17.  
  18. game.ReplicatedStorage:WaitForChild("OnItemBought").OnServerEvent:Connect(function(plr, itemBought)
  19.    
  20.     if itemBought and itemBought:IsA("Tool") and itemBought.Parent == items then
  21.        
  22.        
  23.         local cash = plr.leaderstats.Cash
  24.        
  25.         if cash.Value >= itemBought.ShopGuiInfo.Price.Value then
  26.            
  27.             cash.Value -= itemBought.ShopGuiInfo.Price.Value
  28.            
  29.             itemBought:Clone().Parent = plr.Backpack
  30.         end
  31.     end
  32. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement