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

Changing multiple children in one line?

Asked by 5 years ago

None of this is red

Outputs not saying anything is wrong

Its just not working

workspace.Music.Music:GetChildren().Volume = 0

Music is a folder and I'm trying to change all of the audios inside of it to the volume 0 But its just not working

Any ideas as to why its not working?

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

:GetChildren() is a function used to get the children of an instance and returns it as an array. Since this gives you an array, you could use a generic for-loop to iterate through every child/value in the array.

local MusicFolder = workspace.Music --Gets the folder of music

for _, song in ipairs(MusicFolder:GetChildren()) do
    if song:IsA("Sound") then
        song.Volume = 0
    end
end

In the above code, we define our Music folder then get it's children in the loop. The 'song' variable will be the child or value in the array. We then set it's Volume if it's a Sound object.

If I missed anything or you need anything explained let me know.

GetChildren()

Ad

Answer this question