Advertisement
HowToRoblox

CrateServer

Jan 27th, 2021
4,802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. game.Players.PlayerAdded:Connect(function(p)
  2.    
  3.    
  4.     local ls = Instance.new("Folder")
  5.     ls.Name = "leaderstats"
  6.     ls.Parent = p
  7.    
  8.     local cash = Instance.new("IntValue")  
  9.     cash.Name = "Cash"
  10.     cash.Value = 100000
  11.     cash.Parent = ls
  12. end)
  13.  
  14.  
  15. local crates = game.ReplicatedStorage:WaitForChild("Crates")
  16.  
  17.  
  18. game.ReplicatedStorage.CrateRE.OnServerEvent:Connect(function(plr, crateType, crateTime)
  19.    
  20.    
  21.     if crates:FindFirstChild(crateType) then
  22.        
  23.  
  24.         local price = crates[crateType].Price.Value
  25.        
  26.         if plr.leaderstats.Cash.Value >= price then
  27.            
  28.             plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - price
  29.            
  30.            
  31.             local unboxableWeapons = crates[crateType]:GetChildren()
  32.            
  33.             local chosenWeapon
  34.             repeat chosenWeapon = unboxableWeapons[math.random(#unboxableWeapons)]; wait() until chosenWeapon:IsA("Tool")
  35.            
  36.            
  37.             game.ReplicatedStorage.CrateRE:FireClient(plr, chosenWeapon)
  38.            
  39.            
  40.             wait(crateTime + 1)
  41.            
  42.             chosenWeapon:Clone().Parent = plr.Backpack
  43.         end
  44.     end
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement