Making GUI that Clones Models?
How do I make a GUI that, when you press a specific button, it clones a model? (Car for my specific case.)
I am attempting at making this but with no good results, here is a little instruction set on how it works:
- GUI Opens Up with a list of available cars to select (Spawn)
- Next, once you click the car (Image Button) you would like to spawn, a new gui on the side will appear with a Select Button, the Car Stats (These are not really important) and the Car's Name.
- Once you click the Select button, it finds the selected car name and sets off a remoteEvent with the carName variable attached to it
- Once the remoteEvent starts (Called SpawnCar) a server sided script should get the carName and search for that carName in the cars folder in the serverStorage
- Then if the car is found it will clone it, change the name to plrName"sCar", and move it to the workspace
Here is the code that I made:
Spawn Car Script (Server Sided Script):
03 | local event = game:GetService( "ReplicatedStorage" ):WaitForChild( "CarEvent" ).SpawnCar |
07 | event.OnServerEvent:Connect( function (plr, carName) |
09 | local car = game:GetService( "ServerStorage" ):WaitForChild( "Cars" ):FindFirstChild(carName) |
10 | local cloneCar = car:Clone() |
11 | cloneCar.Parent = workspace |
12 | cloneCar.Name = plr.Name.. "sCar" |
13 | cloneCar:SetPrimaryPartCFrame(workspace.CarMovePart.CFrame) |
14 | plr.Character.HumanoidRootPart.CFrame = workspace.CarMovePart.CFrame |
GUI Button Script (Client Sided LocalScript):
03 | local currentFrame = script.Parent.Parent.Parent |
04 | local button = script.Parent |
06 | local camera = workspace.Camera |
07 | local garageCamera = workspace.Garage.GarageCamera |
08 | local carCamera = workspace.Garage.CarCamera |
09 | local focusPoint = workspace.Garage.CarSpawnPart 3 |
10 | local selectFrame = script.Parent.Parent.Parent.SelectFrame |
11 | local rs = game:GetService( "ReplicatedStorage" ) |
12 | local carName = script.Parent.Parent.CarName.Value.Text |
16 | button.MouseButton 1 Click:Connect( function () |
17 | local showCar = focusPoint:WaitForChild( "ShowCar" ) |
18 | if debounce = = false then |
21 | currentFrame:TweenPosition(UDim 2. new( 0.26 , 0 , 1.081 , 0 ), "Out" , "Quad" , 0.5 , false ) |
22 | camera:Interpolate(garageCamera.CFrame, focusPoint.CFrame, 1 ) |
23 | selectFrame:TweenPosition(UDim 2. new(- 0.651 , 0 ,- 1.58 , 0 )) |
25 | selectFrame.Visible = false |
27 | currentFrame.Visible = false |
29 | rs.CarEvent.SpawnCar:FireServer(carName) |
So, each time I run it it gives off the error: ServerScriptService.SpawnCarScript:10: attempt to index nil with 'Clone'
Any help would be appreciated, thanks.
Also, I did it this way instead of hard coding the name of the car into the code to keep it more flexible and just be able to duplicate the script and make it work even with a different button, It is ran on Studio for testing (Play Button)
Screenshots of this:
Before Pressing Select Button:
https://prnt.sc/55F4UFMs6WSM
After Pressing the Select Button (Look at Bottom):
https://prnt.sc/7VCZ9UIUBZkb