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

How To Make all things in Workspace Change color?

I think it would be this

while true do
function onClick(PlayerClicked)
script.game.Workspace.BrickColor = BrickColor.random()
wait(8.4)
end

Im not sure though Could you please tell me if this would work, and if it doesn't why and an example on how it should be made, If you could I would Love it thank you.

2 answers

✓ Accepted answer

The Workspace does not have a BrickColor property, so you could predict that this wouldn't work.

Instead, you need to find the objects in the Workspace.

To find all "immediate children" (the things in the workspace but not in submodels) you can use :GetChildren().

function onClick()
	local children = Workspace:GetChildren();
	-- children is a table of objects that we iterate over.
	for i = 1,#children do
		if children[i]:IsA("BasePart") then
			-- Since it will error if children[i] is not a part
			-- (doesn't have BrickColor) we check that it is a part.
			children[i].BrickColor = BrickColor.random();
		end
	end
end

Your definition of the onClick function however was wrong... It should look like the above script plus one additional line like this:

SomeClickDetectorValue.MouseClick:connect(onClick);

1 comment

0

This Really had not helped me much But thank you for the Help Much appreciated.

This will not work for a number of reasons: 1) The while loop isn't necessary. 2) The .MouseClick function is also unnecessary 4) game isn't a valid child of script. game is highest part of the hierarchy. 5) Workspace does not have a BrickColor property.

Here's what you need: GetChildren() method A refresher on hierarchy

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