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

How to clone hats or a classname ?

I want to clone a Accessory but it doesn't work...

Script :

Player.Character[Accessory]:Clone()

3 comments

0

What do you mean by "clone hats or a classname"?

0

You want to clone accessories using their classname? I'm not sure what your example there is trying to do

0

im trying to clone a hat but player can wear different hats so im making a script that clone it

2 answers

✓ Accepted answer

If you want to clone Instances by searching their Classname this might be tricky, but using a For Loop it's easy!

First we need to search through the character and get all of it's items.

local Character = Player.Character:GetChildren() -- a table with all the children

for _, object in pairs(Character) -- we get all objects from the table (we get all the children) _ means blank
	print(object.Name) -- prints out their name
end

We also need to ensure that the object is an Accessory. Then we're gonna clone it! Remember, always parent the clones after cloning objects!

local Character = Player.Character:GetChildren() -- a table with all the children

for _, object in pairs(Character) -- we get all objects from the table (we get all the children) _ means blank
	if object:IsA("Accessory") then -- check if the object is an accessory
		local clone = object:Clone()
		clone.Parent = workspace -- puts the hat in workspace
	end
end

Note that the script clones all accessories.

And now we are done!

local accessory = Player.Character[Accessory]
accessory:Clone().Parent = accessory.Parent

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