Model Change Color

Does anyone know a way to change a models color (All of the parts in the model) This means that if I have a model such as a red airplane, I can change it to an orange airplane quickly without having to go into the model and change all the parts of the model to color orange. This would be a very tedious and time consuming task, and I would like to avoid this if I can :confused: Please reply :slight_smile:

3 Likes

I have no ideo what this means… sorry :confused:

1 Like

You first need to get all the children in the model. First start of by writing this.

for i, model in pairs(workspace.MODELNAME:GetChildren()) do

You just got all the children in the object, now you need to specify what object it is.

if model:IsA('Part') then
Your using your variables (like where it belongs in the table) and typing IsA to know what exact object it is, We’re going to find a part.

Now lets change the brickcolor of all the parts we’ve collected in the table.

model.BrickColor = BrickColor.new(COLOR)

hope this helps, im short to explain something i know

6 Likes

it’s like iterators but using for i,v in ipairs. There again it’s like another table of objects

Where do I put the script / local script cause thats probably why its not working for me.

You’ll need a script (SERVER SCRIPT). Copy this code if you believe you can use it if you can understand what it does. That was just an example.

Create a script and place it in your model, or the ServerScriptService, or in the workspace

local ModelObject = workspace.ModelObject
local BrickColorName = 'Really red' -- Must be a brickcolor name.

for i, model in pairs(ModelObject:GetChildren()) do
	if model:IsA('Part') then
		model.BrickColor = BrickColor.new(BrickColorName)
	end
end
11 Likes

It was an example ohh thanks :smiley: I really learn alot in dev forum

pairs performs its loop in iterations. As GetChildren returns a table, please use ipairs instead. pairs should only be used in the case of dictionaries.

i just used pairs in that example as i don’t see a lot of programmers use ipairs

I think pairs should be deprecated and use ipairs for new work

You may not be up to times then. ipairs is commonly used where necessary. This is more of an antiquated belief since pre-LuaU, it was reported that ipairs was slower than pairs.

pairs should not be deprecated because it still has utility for traversing tables where the key is arbitrary. pairs and ipairs each have their own use cases and idiomatic acceptances. pairs should be used for dictionaries and ipairs for arrays.

ipairs is for arrays - tables whose indices are integers beginning with 1. Use pairs for anything else.

So where it says ModelObject in the script I replace that with the Models name?

yes β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž

1 Like