Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you clone a existing model with Instances if so how?

I have a boat model inside workspace with children inside it. I was wondering if I could clone it in a function with an instance and then move where it is on the Axis of the world, but i am grappling with the fact of the matter. If i were to do the script it would be something like

function begingame()
  newboat = Instance.new("BoatModelName")
  newboat.Position = X,Y,Z
  end
begingame()

if anyone knows a way to do this, find a way around it, or do it in a different "way", then help me please. Thankyou for your time.

1 answer

✓ Accepted answer

Instances in ROBLOX have a clone method which will create a copy of the instance and give you the new reference.

First, you would need to set a reference to your model that you want to clone. If, for example, your model you want to clone is "Boat" and is placed directly into workspace, you can reference it like so:

local boat = workspace:WaitForChild("Boat")

Now that we have stored the model into the variable boat, we can clone the instance into another variable.

local boatClone = boat:Clone()

At this point, you may freely manipulate boatClone! If you want to change the position:

-- Sets the position of the cloned boat to X=0, Y=0, Z=0.
boatClone.position = Vector3.new(0, 0, 0)

This is what the compiled script might look like:

-- Get the reference to the boat instance
local boat = workspace:WaitForChild("Boat")

-- An example of a function that will clone the boat and move it to a specified position
local function spawnNewBoatAtPos(x, y, z)
	local boatClone = boat:Clone()
	boatClone.position = Vector3.new(x, y, z)
end

-- A sample call to the function at X=13, Y=2, Z=10
spawnNewBoatAtPos(13, 2, 10)

Hope this helps! :)

5 comments

0

Any way you could edit and explain how I could use the X Y Z paramaters? would help even more! Ill give extra points for it

0

In the function definition, if you accept parameters (x, y, z), then calling the function you simply input 3 values to represent x, y and z respectively.

0

Ohhh ty

0

Another question ; there is a attached seat to the boat ; how would i move the seated player along with it?

0

You would have to check the player that is seated in the player and teleport the player accordingly. There is a property on the seat to see who is sitting on it.

This discussion is preserved as it was. New answers, comments, and votes are closed.