Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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
0
If you don't understand, here is what I am doing. https://ibb.co/kZ3edF IamTewsmrt 6 — 7y
0
If my answer was sufficient, there's an "accept answer" button beneath it :) Perci1 4988 — 7y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

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
0
Thanks! I am SUCH a noob at coding lol IamTewsmrt 6 — 7y
Ad

Answer this question