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

How to clone hats or a classname ? [closed]

Asked by 6 years ago

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

Script :

Player.Character[Accessory]:Clone()
0
What do you mean by "clone hats or a classname"? TheeDeathCaster 2368 — 6y
0
You want to clone accessories using their classname? I'm not sure what your example there is trying to do Vulkarin 581 — 6y
0
im trying to clone a hat but player can wear different hats so im making a script that clone it xJathur95x 129 — 6y

Closed as Non-Descriptive by User#5423, Programical, Vulkarin, and cabbler

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago

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!

Ad
Log in to vote
-1
Answered by
Griffi0n 315 Moderation Voter
6 years ago
local accessory = Player.Character[Accessory]
accessory:Clone().Parent = accessory.Parent