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!
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
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.