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
4 years ago
local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 964670375 then
        local parts = workspace.Confetti:GetChildren()
        for i,v in pairs(parts) do
            for a,b in pairs(v:GetChildren()) do
                b.Enabled = true
                wait(10)
                b.Enabled = false
            end
            end
                return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

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 4 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 — 4y
Ad
Log in to vote
1
Answered by 4 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):

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 964670375 then
        local parts = workspace.Confetti:GetDescendants()
        for i,v in pairs(parts) do
            if(v:IsA("ParticleEmitter")) then
               spawn(function()
                v.Enabled = true
                wait(10)
                v.Enabled = false
              end)
            end
          end
                return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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

local function searchThroughConfetti(parts)
    for i,v in pairs(parts:GetChildren()) do
                b.Enabled = true
                wait(10)
                b.Enabled = false

        if v:GetChildren() ~= nil then
            searchThroughConfetti(v:GetChildren())
        end 
        end
end

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 964670375 then
            searchThroughConfetti(workspace.Confetti)

                return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

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