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")
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
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
they all have the same names or maybe it has sum to do with the fact that its a meshpart???
the parts being MeshPart shouldn’t matter as they also inherits from the attributes from BasePart… you got no error ? nothing in the output ?
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
eh ? how come ? ha ? are you playing the game with F5 or F8 ? is your script local or server side
my script is inside serverscriptservice and even if i play the game f5 or f8 nothing still happens
let me test, real quick, try restarting your Roblox Studio, maybe your output view didn’t initialize correctly ( which is unlikely )
try changing about 300 leave parts and see if it works because the leave parts in my game is around 250
let me test this real quick buddy
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
okay now i feel dumb thank u so much
i mean GetDescendant would be the same as GetChildren if the Leaves are direct descendant of the workspace
i feel so dumb the leaves arent direct descendants of the workspace bruh its grouped together with models