Advertisement
HowToRoblox

CarGuiHandler

Sep 21st, 2021
2,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local cars = game.ReplicatedStorage:WaitForChild("Cars")
  2.  
  3.  
  4. function makeGui()
  5.    
  6.     for i, child in pairs(script.Parent:GetChildren()) do
  7.        
  8.         if child:IsA("TextButton") then child:Destroy() end
  9.     end
  10.    
  11.    
  12.     for i, car in pairs(cars:GetChildren()) do
  13.        
  14.         local btn = script.CarButton:Clone()
  15.        
  16.         btn.Text = car.Name
  17.        
  18.         btn.Parent = script.Parent
  19.        
  20.        
  21.         btn.MouseButton1Click:Connect(function()
  22.            
  23.             game.ReplicatedStorage.CarSpawnRE:FireServer(car)
  24.         end)
  25.     end
  26. end
  27.  
  28.  
  29. makeGui()
  30.  
  31. cars.Changed:Connect(makeGui)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement