How to random select a child from a part

Hello Everybody,

I have a part with 5 children 1 being the core emitter and 4 being the normal emitters. What I basically need is a way to randomly select 1 of the 4 children but excluding the core emitter. Is there a way I can do that?
Screenshot 2022-08-04 151747

1 Like

Use math.random(1,#Explosion:GetChildren)

local randomEmitter = Explosion:GetChildren()[math.random(1,#Explosion:GetChildren)]
1 Like
local regularEmitters = {}

for _, child in ipairs(explosion:GetChildren()) do
    if child.Name ~= "CoreEmitter" then
        table.insert(regularEmitters, child)
    end
end

local randomEmitter = regularEmitters[math.random(1, #regularEmitters)]
2 Likes