How to Find Every Single Child in A Folder

Im trying to find have the value of every single child without having to put the another script every single time. Im not sure if this will work

	local coinsGiven =  player.CoinNExpGiverForAll:GetChildren("CoinsGivenInStageOne").Value

CoinNExpGiverForAll is the folder and then, as I add more stages I will do

	local coinsGiven =  player.CoinNExpGiverForAll:GetChildren("CoinsGivenInStageOne", "CoinsGivenInStageTwo", "CoinsGivenInStageThree").Value

and so on. I have another idea but because im new to scripting i dont know if it will work.

local coinsGiven =  player.CoinNExpGiverForAll.Children.Value

Because I know it works if children was Parent I was wondering if it would work the other way as well. All I need is a short clear way to put every child that is in the folder “CoinNExpGiverForAll” in one variable.

GetChildren returns a table of all the children in something, to do something with all of them just do this

local coinsGiven = 0

for _,value in pairs(player.CoinNExpGiverForAll:GetChildren()) do
   --Code to do on every child

Sorry that I didn’t explain prior to you making the script but the reason why I need that is because of this.

		if MarkerplaceService:UserOwnsGamePassAsync(player.UserId,DoubleCoingamePassID) then
			coinsGiven *= 2

then if the player has that gamepass then no matter which stage they are in the amount of coins they get will always get doubled. This is why I needed coinsGiven to be defined

What is coinsGiven, is it a variable, a IntValue, so on?

Its an IntValue and the parent is CoinNExpGiverForAll

I assume you want to add the coins given in all stages. If so, then you can do this.

local coinsGiven = 0

for _, coinsGivenInStage in pairs(player.CoinNExpGiverForAll:GetChildren()) do
    coinsGiven += coinsGivenInStage.Value

-- do stuff with 'coinsGiven'
1 Like