Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making GUI that Clones Models?

Asked by 3 years ago

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:

  1. GUI Opens Up with a list of available cars to select (Spawn)
  2. 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.
  3. Once you click the Select button, it finds the selected car name and sets off a remoteEvent with the carName variable attached to it
  4. 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
  5. 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):

01-- Spawn Car Event
02 
03local event = game:GetService("ReplicatedStorage"):WaitForChild("CarEvent").SpawnCar
04 
05-- Finally making the car work
06 
07event.OnServerEvent:Connect(function(plr, carName)
08 
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
15 
16end)

GUI Button Script (Client Sided LocalScript):

01-- Open Menu Frame (Exit Garage and Spawn Car)
02 
03local currentFrame = script.Parent.Parent.Parent -- Current Frame
04local button = script.Parent
05local debounce = false
06local camera = workspace.Camera
07local garageCamera = workspace.Garage.GarageCamera
08local carCamera = workspace.Garage.CarCamera
09local focusPoint = workspace.Garage.CarSpawnPart3
10local selectFrame = script.Parent.Parent.Parent.SelectFrame
11local rs = game:GetService("ReplicatedStorage")
12local carName = script.Parent.Parent.CarName.Value.Text
13 
14-- Closing
15 
View all 34 lines...

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

1 answer

Log in to vote
0
Answered by
extrorobo 104
3 years ago

you also need a instanceClone() script so you can clone it.

heres an example,

-- Get a reference to an existing object local original = workspace.Model -- Create the model copy local copy = original:Clone() -- Parent the copy to the same parent as the original copy.Parent = original.Parent -- Move the copy so it's not overlapping the original copy:SetPrimaryPartCFrame(CFrame.new(0, 50, 0))

Ad

Answer this question