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

How to make ALL identical children function at once?

For a bit of context, I'm trying to make a bell/alarm system for a School game. I'm trying to make identical speaker models play the sound all at once when a button is clicked. I was able to get one speaker working but then the rest won't emit the sound.

I think the issue has something to do with looping, and perhaps the GetChildren instance? I read the Devforum articles on both, but since I'm still a bit stuck I can't be sure. I have only a rudimentary knowledge of scripting, so some suggested reading pertaining to this subject would be incredibly helpful and appreciated!

Essentially, how the models are set up is as follows

  • SpeakerSys (Model)
    • Model1 (Model containing play button.)
      • Speaker (Model with Multiple Clones within the parent model)
      • Center (Part)
        • Bell (Sound)

The play button's script is currently this:

function onClicked()
	Game.Workspace.SpeakerSys.Speaker.Center.Bell:Play()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

So in short: What functions should I familiarize myself with in order to understand how to script what I'm trying to achieve?

3 comments

0

I'd also like to apologize if my question is all over the place, I joined not too long ago just to ask this question :')

0

I'm confused on the layout. Where in the structure does this program belong? Where did the ClickDetector come from? Why is Bell suddenly a child of Center?

0

Hi, @Ziff! Sorry for the lack of explanations in that regard, it's a bit hard to describe without screenshots. Within the parent model (SpeakerSys) there are two children, Model1 (Containing the buttons to play and stop the bell sound, which is where the program is.) and Speaker (Which contains the sounds themselves, I put them in a part named Center so the aren't universal.

1 answer

You can loop through all children of whatever the parent of the sounds are and Play each one of them

for i,v in pairs(Speaker:GetChildren()) do --I assume the Sounds are in Speaker?
     if v:IsA("Sound") --check if the current value is a sound
          v:Play() --plays v if it is a sound
     end
end

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