Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you select all Childs with one variable?

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

✓ Accepted answer

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

3 comments

0

Thanks, Creative Energy.

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.

0

So it is. Making the corrections.

This discussion is preserved as it was. New answers, comments, and votes are closed.