Inserting tables inside other tables with a script

Hi! For some sound design I’m doing, I need to save the initial volume of all sound effects I’m going to use for use in tweens. I’m trying to achieve something like this, but with scripting instead of doing it manually:

image

I came up with this basic script which I expected to work first try…

local soundVolume0 = {}

for _,v in pairs(Engine:GetChildren()) do
	if v:IsA("Sound") then
		table.insert(soundVolume0, {[v.Name] = v.Volume;})
	end
end

print(soundVolume0)

In the end though, I noticed that each sound I inserted is a child of a number, which means I cannot just look their names up when I need that data about them. e.g. soundVolume0["Idle"]

image

Any help?

Hey there,

Instead of using table.insert() you can use

for _,v in pairs(Engine:GetChildren()) do
	if v:IsA("Sound") then
		soundVolume0[v.Name] = v.Volume
	end
end

if no other sound has the same name as another sound then it should work, basically the table should look like this after:

local soundVolume0 = {
	["SoundNameHere"] = 0.5
}
1 Like