HowToRoblox

CashHandler

May 22nd, 2021 (edited)
2,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local chars = game.ReplicatedStorage:WaitForChild("Characters")
  2.  
  3. local classNames = {"Accessory", "Shirt", "Pants", "ShirtGraphic", "BodyColors"}
  4.  
  5.  
  6. game.Players.PlayerAdded:Connect(function(plr)
  7.    
  8.     local ls = Instance.new("Folder", plr)
  9.     ls.Name = "leaderstats"
  10.    
  11.     local cash = Instance.new("IntValue", ls)
  12.     cash.Name = "Cash"
  13.     cash.Value = 10000
  14.    
  15.     local chars = Instance.new("Folder", plr)
  16.     chars.Name = "OwnedCharacters"
  17. end)
  18.  
  19.  
  20. game.ReplicatedStorage.CharacterRE.OnServerEvent:Connect(function(plr, isBuying, character)
  21.    
  22.     if not chars:FindFirstChild(character) then return end
  23.    
  24.     if isBuying and not plr.OwnedCharacters:FindFirstChild(character) then
  25.        
  26.         local price = chars:FindFirstChild(character).Price.Value
  27.         local plrCash = plr.leaderstats.Cash
  28.        
  29.         if price <= plrCash.Value then
  30.            
  31.             plrCash.Value -= price
  32.            
  33.             chars[character]:Clone().Parent = plr.OwnedCharacters
  34.         end
  35.        
  36.        
  37.     elseif not isBuying and plr.OwnedCharacters:FindFirstChild(character) and plr.Character and plr.Character:FindFirstChild("Humanoid") then
  38.        
  39.         for i, descendant in pairs(plr.Character:GetDescendants()) do
  40.            
  41.             if table.find(classNames, descendant.ClassName) or descendant:IsA("Decal") and descendant.Parent.Name == "Head" then
  42.  
  43.                 descendant:Destroy()
  44.             end
  45.         end
  46.        
  47.        
  48.         for i, descendant in pairs(plr.OwnedCharacters[character]:GetDescendants()) do
  49.            
  50.             if table.find(classNames, descendant.ClassName) then
  51.                
  52.                 descendant:Clone().Parent = plr.Character
  53.                
  54.             elseif descendant:IsA("Decal") and descendant.Parent.Name == "Head" then
  55.                 descendant:Clone().Parent = plr.Character.Head
  56.             end
  57.         end
  58.     end
  59. end)
Add Comment
Please, Sign In to add comment