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

Clone into every descendant?

Asked by 8 years ago

What I am attempting to do, is that if a part is a model, then a humanoid is cloned into it, to produce a shadow.

for v = is_A("Model") do
    local h = Instance.new("Humanoid")
    h = game.Workspace:GetChildren()
end

I have absolutely no clue, if this is even REMOTELY close...

2 answers

Log in to vote
1
Answered by 8 years ago

Hey there! Your script was a bit wacky so I'm just gonna go ahead and give you the most efficient and fastest way. What we need to do to accomplish putting a Humanoid in each and every model is the :GetChildren() Method. So lets get to the script:

A = game.Workspace:GetChildren() --This is the most important part. It obviously grabs all the children of workspace

for i,v in pairs(A) do --this will start our loop so that a humanoid can be inserted into every model
    if v.ClassName == "Model" then -- this checks wether or not a child is a humanoid. remember that v represents all the models being gathered.
        human = Instance.new("Humanoid") -- this will add a new humanoid
        human.Parent = v -- this will actually insert a humanoid into every model
    end
end

Hope this helps!!

Ad
Log in to vote
0
Answered by 8 years ago

There are a couple problems with your script. One being that the function ":IsA" is spelled incorrectly". Second, a variable cannot act as two objects (though tables can), so trying to representing "h" as both the new "Humanoid" and the Children of the Workspace will NOT work.

Well at least you tried :?

Let's get started. So we know the first error in your script is the first line: `for v = is_A("Model") do --Now I'm not entirely familiar with the "for" operator, so we're going to use a bool (if, then statement). Also, instead of writing the "is_a" function like that, write it like this ":IsA".

if v:IsA("Model") then --checks if "v" is the class name "Model"

end

Next, we'll push the code up above into an interation (more on this here----> http://wiki.roblox.com/index.php?title=Generic_ ).

for i,v in pairs (game.Workspace:GetChildren()) do --we'll grab all the children (object within) the workspace and iterate (run through) all the data

    if v:IsA("Model") then  --checks if "v" is the class name "Model"

    end
end

The final part that needs working on is the "Humanoid creation". --Once we make sure "v" is a Model, then we will create a new "humanoid", and set it's parent (location) inside that model.

for i,v in pairs (game.Workspace:GetChildren()) do --we'll grab all the children (object within) the workspace and iterate (run through) all the data

    if v:IsA("Model") then  --checks if "v" is the class name "Model"
        Humanoid = Instance.new("Humanoid",v) --this will create a new "humanoid" instance and stuff it into the model were using

    end
end

Answer this question