How to get a selection inside of a selection?

Hey guys!
So basically i have been wanting to create a vehicle dealership system in my game, where if you need to add a car all you need to do is duplicate a folder, and make a new car utilizing the code from the other cars and just edit some values.
I was able to get the car buying system to work, however I had ran into some problems with loading the data, in which my script does not know what to select what to load.

THE PROBLEM
My save system is based off of a folder inside the player, in which it contains all the info about the car
and what the player has selected (however currency will be leaderstats when i decide to add it in).

What i need is to make a selection inside of a selection, since my folders are separated into the brands
of that car’s real life counterpart, in which it will select all of the brands inside the folder, and select the
folders of the cars, and then it should load all the customization pieces and stuff.

goofy playersave

I basically get a error in the output where it tells me that its a “missing method” or something
really weird.

WHAT I NEED

Kinda simple really, i need to find out how to select every folder inside of a selection of folders, and i
only want the folder and not any of it’s children to be selected.

THE SCRIPT

	local Brand = PlayerSave.Cars:GetChildren()

	for i, Car in pairs(Brand:GetChildren()) do
		print(Car.Name)

		--goofy save stuff go here when i figure out the funny
	end

Help would greatly be appreciated, thx! :smiley:

Just as the error says your trying to call :GetChildren() on a table.

Brand here is going to be a table of all the brands folders.

I believe you want to loop through the folder contains all the brands, get the brand and loop through that brand folder to get the cars. Something like this should do:

local Brands = PlayerSave.Cars:GetChildren()

for _, Brand in Brands do
    for i, Car in pairs(Brand:GetChildren()) do
        print(Car.Name)

	     --goofy save stuff go here when i figure out the funny
	end
end
1 Like

Iterate through every Descendant.

for _,item in Brand:GetDescendants() do -- Iterates through Descendants
   if item:IsA("Folder") then -- If Item during Iteration is a Folder
      -- some code here for the folders
   else
      continue -- Skips Other Items ( Not really necessary )
   end
end

1 Like

OMG THANK YOU GOT IT TO WORK HOLY SMOKES
:partying_face: :partying_face: :partying_face: :partying_face: :partying_face: :partying_face:
also good job explaining it to me thx thx thx thx thx thx

kinda a stupid mistake on my part but i just didnt notice it lol

aight i wanna thank ya’ll for tryna help me this is very very very greatly appreciated i havent actually gotten a response from a forum post ever thanks you all

idk how to close a post tho, that might be a problem :grimacing:

image

1 Like

The Topic closes 14 automatically after a Solution has been given

Other than that:

  • Delete the Topic
    only works if there are no replies

  • Flag the Topic
    Request for the Mods to Close it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.