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

Painting multiple parts in a random loop?

Asked by
eggxie 2
5 years ago

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

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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)
0
So simple! Thanks for the help! eggxie 2 — 5y
Ad

Answer this question