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

Changing the name of something you clone?

Asked by
Bman8765 270 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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"
0
This works, thanks! Bman8765 270 — 10y
0
Glad I could help! Shawnyg 4330 — 10y
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. cheaterdude12 125 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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!

Log in to vote
0
Answered by 10 years ago

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';};

Answer this question