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

How to change the property of all parts in a model?

How would I change the property of all parts in a model? Is there a way?

Thanks!

2 answers

Apple's code is nice but here is a more flexible one (Recursive too!)

function SetProperties(Item,Class,PropName,Value,Recursive)
	if Item and PropName and Class and Value~=nil then
		for _,v in pairs(Item:GetChildren()) do
			if v.ClassName==Class then
				if v[PropName] then
					pcall(function() v[PropName]=Value end)
				end
				if Recursive then
					SetProperties(v,PropName,Value,Recursive)
				end
			end
		end
	end
end
SetProperties(PathToModel,"Part","Name","Name of Part",true)

Assume the model is named "Model" and is in workspace, and the property you're looking for is "Property", and the value you want is "Value". Also assume the type of object is a Part

for _,v in pairs(game.Workspace.Model:GetChildren()) do
	if v:IsA("Part") then
		v.Property = Value
	end
end

First line loops through the model making v equal to the child for each child, next checks if the child is the correct type of object, then everything before the end is in the loop that messes with each individual child.

This only works for direct children of the model, by the way, so if there's a model inside the model it won't work.

The second line can also be replaced with any other sort of check, but needs to make sure it only edits the parts you want it to.

2 comments

0

You'd also want to check if the item is actually a part and not, for instance, a script, or a dog

0

yes, I forgot about that, thanks~ i'll add it

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