Advertisement
HowToRoblox

CrateClient

Jan 27th, 2021
4,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. local crates = game.ReplicatedStorage:WaitForChild("Crates")
  2.  
  3.  
  4. local gui = script.Parent
  5.  
  6. local cratesGui = gui:WaitForChild("CratesGui")
  7. local unboxGui = gui:WaitForChild("UnboxGui")
  8.  
  9.  
  10. local isOpeningCrate = false
  11.  
  12.  
  13. local minTime, maxTime = 5, 10
  14. local minCells, maxCells = 15, 50
  15.  
  16.  
  17. local openGui = gui:WaitForChild("OpenCrateGui")
  18.  
  19. openGui.MouseButton1Click:Connect(function()
  20.    
  21.     if isOpeningCrate then return end
  22.    
  23.     cratesGui.Visible = not cratesGui.Visible
  24. end)
  25.  
  26.  
  27. for i, crate in pairs(crates:GetChildren()) do
  28.    
  29.     local crateName = crate.Name
  30.     local cratePrice = crate.Price.Value
  31.    
  32.    
  33.     local clonedTemplate = script:WaitForChild("BuyCrateTemplate"):Clone()
  34.    
  35.     clonedTemplate.CrateInfo.Text = crateName .. "\nPrice: " .. cratePrice
  36.    
  37.    
  38.     clonedTemplate.Parent = cratesGui:WaitForChild("CratesScroll")
  39.    
  40.    
  41.     clonedTemplate.MouseButton1Click:Connect(function()
  42.        
  43.        
  44.         if not isOpeningCrate then
  45.            
  46.             isOpeningCrate = true
  47.            
  48.            
  49.             local cells = math.random(minCells, maxCells)
  50.             local unboxTime = math.random(minTime, maxTime)
  51.            
  52.             game.ReplicatedStorage.CrateRE:FireServer(crateName, unboxTime)
  53.            
  54.            
  55.             local connection
  56.            
  57.             connection = game.ReplicatedStorage.CrateRE.OnClientEvent:Connect(function(chosenWeapon)
  58.            
  59.            
  60.                 local weaponCell = math.random(7, cells - 7)
  61.                
  62.                 local weaponVPF
  63.                
  64.                
  65.                 unboxGui.WeaponsClipping.Scroller.Size = UDim2.new(0, cells * unboxGui.WeaponsClipping.Scroller.AbsoluteSize.Y, 1, 0)
  66.                 unboxGui.WeaponsClipping.Scroller.Position = UDim2.new(0, 0, 0, 0)
  67.                 unboxGui.WeaponsClipping.Scroller:ClearAllChildren()
  68.                
  69.  
  70.                 for i = 1, cells do
  71.                    
  72.                    
  73.                     local vpf = Instance.new("ViewportFrame")
  74.                    
  75.                     local weapon
  76.  
  77.                     if i ~= weaponCell then
  78.                        
  79.                         repeat weapon = crates[crateName]:GetChildren()[math.random(#crates[crateName]:GetChildren())]; wait() until weapon:IsA("Tool")
  80.                        
  81.                     else
  82.                         weapon = chosenWeapon
  83.                         weaponVPF = vpf
  84.                     end
  85.                    
  86.                    
  87.                     local clone = weapon.Handle:Clone()
  88.                     clone.Parent = vpf
  89.                    
  90.                     clone.Anchored = true
  91.                    
  92.                     local cam = Instance.new("Camera")
  93.                     cam.Parent = vpf
  94.                    
  95.                     cam.CFrame = CFrame.new(clone.Position + Vector3.new(0, 0, 3), clone.Position)
  96.                    
  97.                     vpf.CurrentCamera = cam
  98.  
  99.                    
  100.                     vpf.Size = UDim2.new(0, unboxGui.WeaponsClipping.Scroller.AbsoluteSize.X / cells, 1, 0)
  101.                     vpf.Position = UDim2.new(0, vpf.AbsoluteSize.X * (i - 1), 0, 0)
  102.                    
  103.                    
  104.                     vpf.Parent = unboxGui.WeaponsClipping.Scroller
  105.                 end
  106.                
  107.                 cratesGui.Visible = false
  108.                 unboxGui.Visible = true
  109.                
  110.                
  111.                 local offset = math.random(-weaponVPF.AbsoluteSize.X/2, weaponVPF.AbsoluteSize.X/2)
  112.                 local distance =  (weaponVPF.AbsolutePosition.X + (weaponVPF.AbsoluteSize.X / 2)) - unboxGui.Marker.AbsolutePosition.X
  113.                
  114.                 unboxGui.WeaponsClipping.Scroller:TweenPosition(UDim2.new(0, -distance + offset, 0, 0), "InOut", "Quint", unboxTime)
  115.                
  116.  
  117.                 wait(unboxTime)
  118.                 isOpeningCrate = false
  119.                 unboxGui.Visible = false
  120.                
  121.                 connection:Disconnect()
  122.             end)
  123.         end
  124.     end)
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement