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

The first part is the only thing gaining the color change?

So, I am a beginner at scripting and wanted to try something out that I learned using the basics. I wanted to make an endless supply of brick to spawn and stack before falling, and I wanted all of them to be different colors. I got the spawning right, but only the first brick changes color. How do I fix this?

while true do
	Instance.new("Part", Workspace)
	game.Workspace.Part.BrickColor = BrickColor.Random()
	wait(0.1)
end

2 comments

0

If you don't understand, here is what I am doing. https://ibb.co/kZ3edF

0

If my answer was sufficient, there's an "accept answer" button beneath it :)

1 answer

✓ Accepted answer

game.Workspace.Part is fine and dandy when there's only one Part in workspace. But when there's more than one Part in workspace, how does the script know which one you want? It doesn't.

What you need to do is save the Part you just created in a variable, and then use that variable to change its color. This way you will always be changing the color of the Part that was just created.

while true do
    local newPart = Instance.new("Part", Workspace)
    newPart.BrickColor = BrickColor.Random()
    wait(0.1)
end

1 comment

0

Thanks! I am SUCH a noob at coding lol

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