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

How to get all children of a child?

Asked by
Jxdenx 45
5 years ago
01local MPS = game:GetService("MarketplaceService")
02 
03MPS.ProcessReceipt = function(receiptInfo)
04    if receiptInfo.ProductId == 964670375 then
05        local parts = workspace.Confetti:GetChildren()
06        for i,v in pairs(parts) do
07            for a,b in pairs(v:GetChildren()) do
08                b.Enabled = true
09                wait(10)
10                b.Enabled = false
11            end
12            end
13                return Enum.ProductPurchaseDecision.PurchaseGranted
14    end
15end

It only enables one of the ParticleEmitter, instead of all the ones inside all the parts. I've used GetDescendants, does the same thing.

3 answers

Log in to vote
2
Answered by 5 years ago

Iterate through parts:GetDescendants() and check if v:IsA("ParticleEmitter"). If so, v.Enabled = true. It should solve your problem and eliminate the need for looping twice.

0
Yeah this would be easier. Technically it does loop as many times as there are children but we don't have to code it up because it's coded up somewhere else lol SethHeinzman 284 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

The problem here is you're waiting 10 seconds between each iteration. What you could do to 'fix' that is this (as well as using 1 loop):

01local MPS = game:GetService("MarketplaceService")
02 
03MPS.ProcessReceipt = function(receiptInfo)
04    if receiptInfo.ProductId == 964670375 then
05        local parts = workspace.Confetti:GetDescendants()
06        for i,v in pairs(parts) do
07            if(v:IsA("ParticleEmitter")) then
08               spawn(function()
09                v.Enabled = true
10                wait(10)
11                v.Enabled = false
12              end)
13            end
14          end
15                return Enum.ProductPurchaseDecision.PurchaseGranted
16    end
17end
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

If descendants doesn't work, which is most likely will.

I'm going to show you something cool that's an alternative.

01local function searchThroughConfetti(parts)
02    for i,v in pairs(parts:GetChildren()) do
03                b.Enabled = true
04                wait(10)
05                b.Enabled = false
06 
07        if v:GetChildren() ~= nil then
08            searchThroughConfetti(v:GetChildren())
09        end
10        end
11end
12 
13MPS.ProcessReceipt = function(receiptInfo)
14    if receiptInfo.ProductId == 964670375 then
15            searchThroughConfetti(workspace.Confetti)
16 
17                return Enum.ProductPurchaseDecision.PurchaseGranted
18    end
19end

So instead of having two for loops you can call the function again if you need to search the child's children by passing the Child as the new parts. Not sure if this above would work cause I rushed the code but I'm just trying to express the way I go about searching through a childs children. It's just nicer to me to not have two for loops.

The problem was already solved way better than this, but this can also be applied to tables and such.

Answer this question