Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do I make a script affect every part in a group?

im trying to change the color of every part in a group and I dont know how to do it, ive tryed to do an in pairs thing and it only changed one parts color in the group

this is what my script looks like

while true do 
	for i, v in pairs(game.Workspace:WaitForChild('stage1').stagetest:GetChildren()) do

		if v:IsA('Part') then 

			wait(math.random(1,5))

			v.BrickColor = BrickColor.new("Lime green")


			wait(math.random(1,5))
			v.BrickColor = BrickColor.new("Really red")


		end
	end
end

im trying to affect items in a group that is inside of another group so thats why its stage1.stagetest

1 answer

you might have been doing it wrong, so try this:

for i,v in pairs(script.Parent:GetChildren()) do
      if v:IsA("Part") then
           v.BrickColor = BrickColor.new("Your color")
    end
end

put the script inside the model for it to work. Hope it works!

3 comments

0

it still didnt work for me but i edited the question to show my script

0

Sorry man, I've been trying everything i can but i dont really know how i can fix it.It seems though that the waits are the problem, because it waits for those until it moves onto the next part. I hope you find an answer!

0

I, myself am not the best at scripting lol

This discussion is preserved as it was. New answers, comments, and votes are closed.