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

Why Won't this GetChildren() and Clone() work?

Asked by 9 years ago

Hey! So now I am attempting to make a Bloom Effect using custom particles. Basically what I'm trying to do is make the ParticleEmitter to be cloned into every part in the Workspace but this isn't working. I am using a :GetChildren to get all the parts in the workspace (Obviously) and using Clone() to cloen the emitter in one block to put it in all the parts.

A = game.Workspace:GetChildren()
Emit = game.Workspace.Emitter.Particle:Clone()

for i,v in pairs(A) do
if v.className == "Part" then
Emit.Parent = v
end
end

Nothing is in the output again so I don't know what to do or what is wrong. Thanks! ~Minikitkat

2 answers

Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

Just put the cloning line in the loop like this

A = game.Workspace:GetChildren()

for i,v in pairs(A) do
if v.className == "Part" then
Emit = game.Workspace.Emitter.Particle:Clone()
Emit.Parent = v
end
end
0
Oh, That simple? Interesting. Thanks! minikitkat 687 — 9y
1
Oh, and put local Emit instead of just Emit, since it's in a scope. funyun 958 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

I see what you're trying to do, but most of the time, shortcuts don't work like that.

You need to clone the emitter in the for loop and then set it's parent to the part. I would also recommend you "tab out" your code as it looks a lot cleaner.

A = game.Workspace:GetChildren()
Emit = game.Workspace.Emitter.Particle

for i,v in pairs(A) do
    if v.className == "Part" then
        local e = Emit:Clone() --We now clone the emitter every time a part is detected.
        e.Parent = v --Set the clone's parent to the part.
    end
end

However, that will only work for parts. What about wedge parts and unions? You can use IsA for the wedge parts to check if the part is a BasePart. You can also add in another condition using and for the Union Operations.

A = game.Workspace:GetChildren()
Emit = game.Workspace.Emitter.Particle

for i,v in pairs(A) do
    if v:IsA("BasePart") or v:IsA("UnionOperation") then --Checks if the part is a part or a union.
        local e = Emit:Clone() --We now clone the emitter every time a part is detected.
        e.Parent = v --Set the clone's parent to the part.
    end
end
1
Ninja'd. Sorry, funy. :) Spongocardo 1991 — 9y
0
s'ok mang funyun 958 — 9y

Answer this question