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)
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)