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

Get all parts with the same name?

Asked by 8 years ago

Hi all! I was wondering how you would get the name of a part in the workspace that has the same name? For example if there are lots of parts called "Blue" and they had lights in, how would I "Find" them all and "access" the lights?

I tried FindFirstChild and GetChildren, but it didn't work :/ Thanks!

0
You would want to use a for loop gathering all children of a model. Have an if statement that if the Part's name equals blue, then to change the light object. Either that or place the object values into another table and go through that. Without an attempt present, we can not help. M39a9am3R 3210 — 8y

3 answers

Log in to vote
2
Answered by 8 years ago

I take more Direct approaches so I'll give you an Example code:

local Parts = game.Workspace:GetChildren() for i = 1, #Parts do if Parts[i].Name == "Blue" then Light = Parts[i].Light -- Insert coding for the Lights else return end end


Basically what I did was GetChildren() in Workspace then check for Objects Named "Blue" then when the script gathered all the Objects named "Blue" it would go into each one and find the Child, "Light".... I hope that made sense. I'm trying to get use to Explaining this. xD

Ad
Log in to vote
0
Answered by
DevChris 235 Moderation Voter
8 years ago

function scanInWorkspace(placeToScan) for _,object in pairs(placeToScan:GetChildren()) do scanInWorkspace(object) if object:IsA("BasePart") and object.Name == "Blue" then local light = object:FindFirstChild "PointLight" if light then -- Code end end end end scanInWorkspace(workspace)

This function will go through all the children of "placeToScan." The function runs itself again on each child, therefore checking through the whole hierarchy. If the object meets the criteria, it will run code.

Log in to vote
-1
Answered by 8 years ago

You could just change the names of both of them lol

Answer this question