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

Changing the name of something you clone?

Here is my cloning script:

game.ServerStorage.Cardone:Clone().Parent = script.Parent.Parent

How do I change the name of the item I'm cloning in its new spot

3 answers

✓ Accepted answer

Well, one way is just by saying

script.Parent.Parent.Cardone

But, that may not be as easy as it seems, as some people clone an object multiple times. You would set a variable for the clone, so

clone = game.ServerStorage.Cardone:clone()
clone.Parent = script.Parent.Parent
clone.Name = "Hi"

3 comments

0

This works, thanks!

0

Glad I could help!

0

While this would surely work, it'd be a great idea to look into scopes. Is 'clone' a global variable? A local variable? Depends on where this code runs.

Simple, heres how;

local Cardone = game:WaitForChild("ServerStorage"):WaitForChild("Cardone"):Clone() --This will repeat waiting until 'ServerStorage' has loaded, and 'Cardone' has loaded into 'ServerStorage', and when loaded, will set the 'Clone' method of 'Cardone'; The 'Clone' method clones a instance, like a copy of something
Cardone.Parent = script.Parent.Parent --This will set 'Cardone''s Parent
Cardone.Name = "Cardone" --This will set the name of the Cloned 'Cardone'

Hope this helped!

Or, you could try out my custom cloning function that allows you to set properties much easier.

function cloneWithProperties(obj)
if not(type(obj)=='userdata') then return end;
local newi = obj:Clone();
return function(props)
if not(type(props)=='table') then return end;
for i,v in pairs(props) do
newi[i] = v;
end;
end;
end;
cloneWithProperties(game.Workspace.Part){Parent = game.Workspace.Model; Name = 'kClone testing';};

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