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

How would i change the name of Cloned Parts?

Asked by 6 years ago

So, i'm making a game ("https://www.roblox.com/games/2440463201/Marble-Fall-ALPHA") Where i'm working so you can destroy walls to make the "Marbles" fall. And, now i'm trying to respawn it. If, you join the game you can see a Settings menu where there are buttons to Destroy/Spawn Walls. My code keeps are giving me a error. How would i fix this?

local Walls = game.Workspace.Walls

Walls:Clone(W2)

W2.Parent = game.ReplicatedStorage

Walls:Destroy()

Defining the Walls. Cloning the walls. How would i change the name of the Cloned Walls? So, then i could change the parent, Destroy the walls, then Change the parent back to Workspace.

2 answers

Log in to vote
1
Answered by 6 years ago

Side note: If you have any errors in your script, remember to post them in the question. We aren't mind readers.

The Instance:Clone() method, when called, will return a copy of the object you called it on. When you do workspace.Part:Clone(), you're cloning the part, but its initial Parent is nil, so you'd have to do workspace.Part:Clone().Parent = workspace to clone it. But what if you wanted to change more properties to the clone, and not the original part? In your case you want to change the name. You would have to store the clone in a variable to prevent any possible conflict with the first Walls, as workspace.Part (in my example) would refer to the first part and not the clone

Clone takes no arguments. If you do pass any arguments to something that doesn't take any arguments or you gave it more arguments than it takes, the additional arguments will simply be discarded.

workspace.Part:Destroy(46) -- Just an example. The 46 is discarded. 

The same is for variables:

local variable = "yes", print, 93
print(variable) --> yes

Prints "yes", as the print function as well as 93 were discarded.

Fix

As I have said, Clone returns a copy of the object you called it on. Let's store that copy in a variable.

local Walls = game.Workspace.Walls
local W2 = Walls:Clone() -- Storing the copy of Walls in a variable.
W2.Parent = game.ReplicatedStorage
W2.Name = "" -- Name goes in between the ""
1
Forgot to mention that according to your code snippet, 'W2' was never defined, so it's an unknown global, and is nil User#19524 175 — 6y
0
Thanks :) Helped alot! :D bobatmcdownalds -2 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Using the Clone function returns an object, so you cannot have it on its own as you have done. Instead, assign it to a variable like so:

local wallsClone = Walls:Clone()

And to change its name, as simple as:

wallsClone.Name = "WallsClone"

Answer this question