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

How do you select all Childs with one variable?

Asked by
Xianon 105
10 years ago
local Stop = script.Parent
local sounds = script.Parent.Parent.Parent.ScrollingFrame:GetChildren().sound

function onClick(Stop)
    sounds:stop()
end

Stop.MouseButton1Click:connect(onClick)

1 answer

Log in to vote
0
Answered by 10 years ago

Helo Xianon,

Great question!

You are off to the right start, so great job.

local Stop = script.Parent
local sounds = script.Parent.Parent.Parent.ScrollingFrame:GetChildren().sound

function onClick(Stop)
    sounds:stop()
end

Stop.MouseButton1Click:connect(onClick)


The first error we can see is the ".sound" on the end of your variable.

Secondly, a 'for' statement would be needed in order to go through

function onClick()
for i,v in pairs(script.Parent.Parent.Parent.ScrollingFrame:GetChildren()) do -- Get all the Children in script.Parent.Parent.Parent.ScrollingFrame
    if v:IsA("Sound") then --Check if 'v' is a sound
        v:Stop() -- Stop it
    end
end
end
0
Thanks, Creative Energy. Xianon 105 — 10y
1
No. This is incorrect. You need to iterate through the table 'sounds', then check if each object is a sound, and then call the 'stop' method on the object. You cannot call IsA or Stop on a table. Articulating 1335 — 10y
0
So it is. Making the corrections. AmericanStripes 610 — 10y
Ad

Answer this question