How do i identify a whole bunch of parts with the same name?

so im trying to create a leaves color changing system and i dont know how to locate all the leaves

this is my code

local Leaves = workspace:FindFirstChildOfClass("MeshPart"):FindFirstChild("Leaves")

you can use a for i, v loop to get multiple object with same name
Example:

for i, v in pairs(workspace:GetChildren()) do
   if v.Name == "Something" then
       -- do something 
   end
end
2 Likes

it doesnt change all the leaves i dont know what to do

for i, v in pairs(workspace:GetChildren()) do
	if v.Name == "Leaves" then
		v.Color = Color3.fromRGB(145, 104, 53)
		
	end
end

the script is technically correct, are you Leaves all with the same names ? or are there some with like “Leave”, “Leaves” “leaves” as it won’t work if yes

1 Like

they all have the same names or maybe it has sum to do with the fact that its a meshpart???

1 Like

the parts being MeshPart shouldn’t matter as they also inherits from the attributes from BasePart… you got no error ? nothing in the output ?

nothing at all for some reason

1 Like

try printing the index value of the for loop at the end, and compare it with the number of leave you have, if the number don’t match we have a problem

1 Like

nothing showed up

1 Like

eh ? how come ? ha ? are you playing the game with F5 or F8 ? is your script local or server side

1 Like

my script is inside serverscriptservice and even if i play the game f5 or f8 nothing still happens

1 Like

let me test, real quick, try restarting your Roblox Studio, maybe your output view didn’t initialize correctly ( which is unlikely )

1 Like

I did test on my side and :

1 Like

still nothing

1 Like

try changing about 300 leave parts and see if it works because the leave parts in my game is around 250

1 Like

let me test this real quick buddy

2 Likes

do you understand how the code work? Ok so basically the code will find everything in workspace that name “Leaves”, if you want to get all of the leaves in the game then use :GetDescendants()

Example:

for i, v in pairs(workspace:GetDescendants()) do
   if v.Name == "Something" then
       -- do something 
   end
end
3 Likes

okay now i feel dumb thank u so much :smiling_face_with_tear:

1 Like

i mean GetDescendant would be the same as GetChildren if the Leaves are direct descendant of the workspace

1 Like

i feel so dumb the leaves arent direct descendants of the workspace bruh its grouped together with models :smiling_face_with_tear:

1 Like