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

Painting multiple parts in a random loop?

I'm still new at scripting and sort of stumped. I've created a loop that can randomly paint some windows, but I want it to randomly select a color and then paint all of the parts the same color. Instead, it randomly paints each part a different color.


 game.ReplicatedStorage.Paint.OnServerEvent:Connect(function(player)
wait (1)

local window = game.Workspace[player.Name.."'s House"].Windows
local b = window:GetChildren()
local children = window:GetChildren()

for i = 1, #children do
	
	local child = children[i]
	
	if children[i].ClassName == "Part" then
				children[i].BrickColor = BrickColor.Random()
			print("painting " .. child.Name)
		
		end
	end
end)



1 answer

What you can do is store a variable with a random colour and change all the the parts' colour to the colour

 game.ReplicatedStorage.Paint.OnServerEvent:Connect(function(player)
wait (1)

local window = game.Workspace[player.Name.."'s House"].Windows
local b = window:GetChildren()
local children = window:GetChildren()
local randColour = BrickColor.Random()

for i = 1, #children do

    local child = children[i]

    if children[i].ClassName == "Part" then
                children[i].BrickColor = randColour
            print("painting " .. child.Name)

        end
    end
end)

1 comment

0

So simple! Thanks for the help!

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