Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I select only a specific group of models from a table?..

... and then select the parts of those specific models that are selected?

Heres a part of my code...

	local mines = script.Parent:GetChildren()
	for i,v in pairs(mines) do
		if v.Name == "Mine" then
			local indicators = 

and these are what I'm trying to select through code:

http://imgur.com/EAtLRiI

thanks in advance!

1 answer

✓ Accepted answer

(Assuming this script is the script from the screenshot,)
Pretty much how you had it. All you have to do after that is index v inside of the if statement, as that would be one of the Mines. Your best bet would be to use FindFirstChild, just to be safe.

local mines = script.Parent:GetChildren()
for i,v in pairs(mines) do
    if v.Name == "Mine" then
        local indicator = v:FindFirstChild('Indicator') --// Get the indicator.
        if indicator then --// check to see if it was found.
            --// do stuff.
        end
    end
end

And that's about all there is to it, for getting the indicators. However, based on your question, I'm assuming you want to put the indicators into a new table, populated with indicators. You can do that using table.insert, or by inserting them using bracket notation.

local indicators = {}; --// create an empty table for the indicators
local mines = script.Parent:GetChildren()
for i,v in pairs(mines) do
    if v.Name == "Mine" then
        local indicator = v:FindFirstChild('Indicator') --// Get the indicator.
        if indicator then --// check to see if it was found.
            indicators[#indicators + 1] = indicator; --// Add the indicator to the table
            --// do stuff.
        end
    end
end

--// Do stuff with the indicators.

Hope this helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.