Help needed with color changing

Hey there! I have a question.
I need to change the color of 904 parts named by the same name. I used the code but it only changes one part at a time and the rest remains the same. I will be glad to receive any help from you. Thank you!

All of these parts are called Snowpart and their location is game.Workspace.Map.Dirt.Grass.Snowpart
Here is my script:

local counter = 0

while counter < 905 do
	wait(0)
	game.Workspace.Map.Dirt.Grass.Snowpart.Material = Enum.Material.Snow
	game.Workspace.Map.Dirt.Grass.Snowpart.BrickColor = BrickColor.new("Institutional white")
	counter = counter + 1
end

Delete your old code and try this instead

for i, v in (workspace.Map.Dirt.Grass:GetChildren()) do -- This loops through every child stored in the 'Grass' Instance.
    if v:IsA("BasePart") and v.Name == "Snowpart" then -- This checks if the children we're looping through are BaseParts and have the name 'Snowpart'
        v.Material = Enum.Material.Snow
        v.BrickColor = BrickColor.new("Institutional white")
    end
end

Also, instead of using wait(), use task.wait() instead.

task.wait() is just better than wait(). There are no difference between both, but wait() can sometimes cause delays when it resumes the thread, so just always use task.wait()

1 Like

This code is very good,it will surely work,but if there is a task.wait()

This code will not work as it actually run one at a time. But since there is no task.wait() this is the correct solution

1 Like

Look at that code that code is correct.

1 Like

This is kinda confusing. Are you referring to my code or her code? :slightly_smiling_face:

Your code later u will know why

1 Like

Wait, does she want the snowparts to change their color one part at a time?

She just want to change all the parts to the same name bruhhhhhh…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.