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

How do I change the properties of an entire model?

I have a model that's roughly 10k parts to be used as terrain. When created, they were all gray, plastic parts. How would I get ALL the children of the model, and then change the properties of said children.

I don't want to select each part and change the properties 10,000 times.

I'm not good with :GetChildren() whatsoever.

1 comment

0

According to roblox and the answers below, you will have to use GetChildren

3 answers

✓ Accepted answer

Insert this in the model filled with the parts and follow the green text in the script. Oh and +1 dis :D

print("Tochi Was Here")
for index,part in pairs(script.Parent:GetChildren()) do
	if part:IsA("Part") or part:IsA("WedgePart") or part:IsA("CornerWedgePart") then do
		--do stuff from here :
		part.BrickColor = BrickColor.Green()
		part.Material = "Grass"
		--to here :D                 
	end
	end
end

Those 10k parts are in a model right? No one leaves TEN THOUSAND PARTS in Workspace ._.

5 comments

0

You are wrong dear sir.

0

I just re-tested it and it works sir. >.<

0

Instead of 'if part:IsA("Part") or part:IsA("WedgePart") or part:IsA("CornerWedgePart") then' you could just check if the the part is a BasePart (if part:IsA("BasePart")).

0

I left it in a model. Who leaves that amount of parts in Workspace?!?!

0

Thanks coo1o! :D



function Scan(model,tab) -- Scans through EVERY object in (model)
	if not tab then tab = {} end
	for _,v in pairs(model:GetChildren()) do
		if v:IsA("BasePart") then
			table.insert(tab,v)
			if #v:GetChildren() > 0 then Scan(v,tab) end
		end
	end
	return tab
end

parts = Scan( Workspace.Model ) -- Edit 'Workspace.Model' with your terrain


for _,v in pairs(parts) do
	v.BrickColor = BrickColor.Green()		-- Edit the parts
	v.Transparency = 0
	--etc
end

1 comment

0

NOTE, this may take time, or lag, depending on how good your PC is.

Here is where I got info from.. http://wiki.roblox.com/index.php?title=API:Instance/GetChildren

Anyways, according to that, if you read it there is a script..

local children = Workspace:GetChildren() -- edit this
for i = 1, #children do
    print(children[i].Name) -- edit this
end

All you need to do is change it to include the model Workspace.(ModelName):GetChildren()

then delete print and put what you want to edit about them inside there.

I believe this should work, but I can't be 100% sure on it because i've never used it yet.

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