Advertisement
HowToRoblox

DealershipClient

Jun 27th, 2022
953
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None
  1. --Open and close GUI
  2. local frame = script.Parent
  3. frame.Visible = false
  4.  
  5. local promptTriggered = nil
  6.  
  7. frame.CloseButton.MouseButton1Click:Connect(function()
  8.     frame.Visible = false
  9.     promptTriggered.Enabled = true
  10. end)
  11.  
  12. game.ReplicatedStorage.CarsRE.OnClientEvent:Connect(function(prompt)
  13.     frame.Visible = true
  14.     promptTriggered = prompt
  15.     promptTriggered.Enabled = false
  16. end)
  17.  
  18.  
  19. --Scrolling frame set up
  20. frame.CarPreviewFrame.Visible = false
  21.  
  22. function setupScrollingFrame(folder)
  23.    
  24.     for i, button in pairs(frame.CarsScrollingFrame:GetChildren()) do
  25.         if button:IsA("TextButton") then
  26.             button:Destroy()
  27.         end
  28.     end
  29.    
  30.     local cars = folder:GetChildren()
  31.     table.sort(cars, function(a, b)
  32.         return a.PRICE.Value < b.PRICE.Value
  33.     end)
  34.    
  35.     for i, car in pairs(cars) do
  36.        
  37.         local newBtn = script.CarButton:Clone()
  38.         newBtn.CarNameLabel.Text = car.Name
  39.        
  40.         local carModel = car:Clone()
  41.         carModel.Parent = newBtn.CarViewportFrame
  42.        
  43.         for x, desc in pairs(carModel:GetDescendants()) do
  44.             if desc:IsA("Seat") or desc:IsA("Script") or desc:IsA("VehicleSeat") or desc:IsA("LocalScript") or desc:IsA("ScreenGui") or desc:IsA("ModuleScript") then
  45.                 desc:Destroy()
  46.             end
  47.         end
  48.        
  49.         local camera = Instance.new("Camera")
  50.         newBtn.CarViewportFrame.CurrentCamera = camera
  51.         camera.Parent = newBtn.CarViewportFrame
  52.        
  53.         camera.CFrame = carModel.CameraPosition.CFrame
  54.        
  55.         newBtn.Parent = frame.CarsScrollingFrame
  56.        
  57.         if i == 1 then
  58.             frame.CarsScrollingFrame.UIGridLayout.CellSize = UDim2.new(0, newBtn.AbsoluteSize.X, 0, newBtn.AbsoluteSize.Y)
  59.         end
  60.        
  61.         newBtn.MouseButton1Click:Connect(function()
  62.            
  63.             frame.CarPreviewFrame.CarNameLabel.Text = car.Name
  64.            
  65.             local price = car.PRICE.Value
  66.             local formatted = price
  67.             while true do  
  68.                 formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2")
  69.                 if k == 0 then
  70.                     break
  71.                 end
  72.             end
  73.             frame.CarPreviewFrame.CarPriceLabel.Text = "$" .. formatted
  74.            
  75.             frame.CarPreviewFrame.CarViewportFrame:ClearAllChildren()
  76.             local carModel2 = carModel:Clone()
  77.             local camera2 = camera:Clone()
  78.             frame.CarPreviewFrame.CarViewportFrame.CurrentCamera = camera2
  79.             carModel2.Parent = frame.CarPreviewFrame.CarViewportFrame
  80.             camera2.Parent = frame.CarPreviewFrame.CarViewportFrame
  81.            
  82.             if folder.Parent == game.Players.LocalPlayer then
  83.                 frame.CarPreviewFrame.CarButton.Text = "SPAWN"
  84.             else
  85.                 frame.CarPreviewFrame.CarButton.Text = "BUY"
  86.             end
  87.            
  88.             frame.CarPreviewFrame.Visible = true
  89.         end)
  90.        
  91.         frame.CarsScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, frame.CarsScrollingFrame.UIGridLayout.AbsoluteContentSize.Y)
  92.     end
  93. end
  94. setupScrollingFrame(game.ReplicatedStorage.Cars)
  95.  
  96.  
  97. --Car buttons
  98. frame.CarShopButton.BackgroundColor3 = Color3.fromRGB(142, 41, 214)
  99. frame.OwnedCarsButton.BackgroundColor3 = Color3.fromRGB(142, 110, 145)
  100.  
  101. frame.CarShopButton.MouseButton1Click:Connect(function()
  102.     frame.CarShopButton.BackgroundColor3 = Color3.fromRGB(142, 41, 214)
  103.     frame.OwnedCarsButton.BackgroundColor3 = Color3.fromRGB(142, 110, 145)
  104.     setupScrollingFrame(game.ReplicatedStorage.Cars)
  105. end)
  106.  
  107. frame.OwnedCarsButton.MouseButton1Click:Connect(function()
  108.     frame.OwnedCarsButton.BackgroundColor3 = Color3.fromRGB(142, 41, 214)
  109.     frame.CarShopButton.BackgroundColor3 = Color3.fromRGB(142, 110, 145)
  110.     setupScrollingFrame(game.Players.LocalPlayer.Cars)
  111. end)
  112.  
  113. frame.CarPreviewFrame.CarButton.MouseButton1Click:Connect(function()
  114.     game.ReplicatedStorage.CarsRE:FireServer(frame.CarPreviewFrame.CarButton.Text, frame.CarPreviewFrame.CarNameLabel.Text, promptTriggered and promptTriggered.Parent.Parent or nil)
  115. end)
Advertisement
RAW Paste Data Copied
Advertisement