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

Select multiple parts at once?

I wanna change the color of all the parts in a character, I use this same code to change the face of them, but this wont work and there are no errors I assume it's because I selected all of the characters parts wrong?

player = script.Parent.Parent.Parent.Parent.Parent
char = player.Character
val = script.Parent.num.numval
nutext = val.Parent
body = char:GetChildren("Torso", "Right Leg", "Right Arm", "Left Leg", "Left Arm", "Head")
	
script.Parent.Up.MouseButton1Click:connect(function()
	val.Value = val.Value + 1
end)

script.Parent.Down.MouseButton1Click:connect(function()
	val.Value = val.Value - 1
end)

script.Parent.num.numval.Changed:connect(function()
	script.Parent.num.Text = "(" .. val.Value .. "/7)"
	if val.Value == 1 then
		body.BrickColor = BrickColor.new("Bright red")
	elseif val.Value == 2 then
		body.BrickColor = BrickColor.new("Bright blue")
	elseif val.Value == 3 then
		body.BrickColor = BrickColor.new("Bright yellow")
	elseif val.Value == 4 then
		
	elseif val.Value == 5 then
		
	elseif val.Value == 6 then
		
	elseif val.Value == 7 then
		
	elseif val.Value == 8 then
		val.Value = 1
	end
end)

I assume it's Line 5 with the problem in how I am selecting the parts? Any help is appreciated

1 answer

✓ Accepted answer

GetChildren returns a table and does not require arguments,

for instance, body:GetChildren() would return

{body.Head, body.Torso body.LeftArm, body.RightArm,body.RightLeg,body.LeftLeg}

table not guarenteed to contain all of that, just an example

you can itterate over all of those items with a for in pairs loop

for key,value in pairs(body:GetChildren()) do
	if(value:IsA("BasePart"))then -- Check if value is a Part
		value.BrickColor = BrickColor.Red
	end
end

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