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

How to get all children sounds in folder and play at different volume?

Asked by
TechModel 118
2 years ago
Edited 2 years ago

Im making this underground music player like a club bunker, and i have added invisible parts covering the enterance and the area. I have a folder with 3 different parts, one at the main entrance playing low audio and area 2 with medium and area 3 which is the club area. I made this script with skip and mute button. The trouble is on line 5 I can't get all of the childrens sound in the folder becuase I don't have a clue yet. The model in line 5 is 3 parts called area with sound parented in it.

local Songs = {
    1876360209,6888740313,786465393,6415424340
}

local SongObject = script.Parent.Folder.Model:GetChildren()
local SkipButton = script.Parent.ProximityPrompt
local MuteButton = script.Parent.Mute.ProximityPrompt

MuteButton.Triggered:Connect(function()
    if SongObject.Volume == 4 then
        SongObject.Volume = 0
        MuteButton.ActionText = "Unmute"
    else
        SongObject.Volume = 4
        MuteButton.ActionText = "Mute"
    end
end)

SkipButton.Triggered:Connect(function()
    SongObject:Stop()
end)

while true do
    for i = 1, #Songs do
        local Song = Songs[i]

        SongObject.SoundId = "rbxassetid://" .. Song
        SongObject:Play()

        repeat wait() until not SongObject.IsPlaying
    end
end
0
Im xonfused on wht ur trying to do, r u trying to play music in the part? Does the aound already exist? AlexanderYar 788 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

You can get all the sounds by using a for loop with pairs. (ipairs are for arrays, but I think you can use both regardless idk about this you should search this one up.)

So here's is how you could put this.

MuteButton.Triggered:Connect(function()
    for _, songs in pairs(SongObject) do -- what this does is, it loops through everything inside of SongObject then changes them or does something with them with the code you put.

        if songs.Volume == 4 then
        songs.Volume = 0
        MuteButton.ActionText = "Unmute"
else
        songs.Volume = 4
        MuteButton.ActionText = "Mute"
    end
    end
end)

Btw I didn't test this so I have no idea if this'll work. It should but not confirmed. Comment if it doesn't.

READ: Also, I don't quite understand what you're saying. Do the sounds already exist inside of a part or something? I'm seeing other code that suggests otherwise.

Ad

Answer this question