Scripting a random part picker color changer

Introduction

I know the title is confusing but I had made a post earlier today about this and other things asking if it was possible. Here is a link to that post: Is this possibile?

In that post I asked 3 questions @EmbatTheHybrid had answered the 1st question. But now I need help with a script that combines question 2 and 3.

For those who have not seen 2 and 3 let me some it up.

The question

Can you refer to all the parts in a folder and make those BrickColor randomly change colors and if the color is a certain color (Red) then the Part CanCoillde is false?

Hopefully that told you what I am trying to do.

More in depth

So I have parts in a folder and I want to make it sp that randomly a parts color changes. But if that color is red then CanCoillde = false.

What I have done so far

I will show you the script I was thinking of. Where there is “” that means I need help making that happen.

local folder = script.Parent


while true do
	"Randomly selects part in folder"
	"Changes the picked parts brick color to random color"
end

if "Checks if part color is red" then
	"Makes part CanCoillde = false"
end

--- Important Notes for scripter looking on DevForum
---1. All the Parts in the folder are named Part

If you have another way of scripting that would be nice too

Can I script?

This is really odd but I can put together scripts like above but cant fully make “Tuff” scripts but I can make some really cool ones.

Hopefully You Can Help
Thank You
-Fan

Simply put: yes.

local folder = script.Parent
local _colors = {
   "Bright red",
   "Bright blue",
   "Bright yellow",
   "Bright purple",
   -- you can go on and insert more different BrickColors here...
}

while wait(5) do -- you can change the 5 to wait as many seconds as you want (this changes the colors every 5 seconds
   local children = folder:GetChildren()
   local randomPart = children[math.random(1,#children())] -- this chooses a random child from folder
   randomPart.BrickColor = BrickColor.new (_colors[math.random(1,#_colors)]) -- sets to random color
   if randomPart.BrickColor == BrickColor.new("Bright red") then
     randomPart.CanCollide = true
   else 
      randomPart.CanCollide = false
   end
end

EDIT: fixed erroring for <EOF>

1 Like
while true do
local ranInt = math.random(1, #script.Parent)
local colorInt = math.random(1, 3) -- Amount of colors here
if colorInt == 1 then
folder[ranInt].BrickColor = BrickColor.new("Really red") -- or whatever
elseif -- other colors
if folder[ranInt].BrickColor.Name = "Really red" then
folder[ranInt].CanCollide = false
end

Here’s my script

local folder = script.Parent:GetChildren()
local RandomColors = {
	BrickColor.new('Really red'), 
	BrickColor.new("Really black"), 
	BrickColor.new("Really blue"), 
	BrickColor.new("Bright green"), 
	BrickColor.new("Bright yellow")
}
while wait(2) do
	local RandomPart = folder[math.random(1, #folder)]
	local Color = RandomColors[math.random(1, #RandomColors)]
	RandomPart.BrickColor = Color
	if Color == BrickColor.new('Really red') then
		RandomPart.CanCollide = false
	else
		RandomPart.CanCollide = true
	end
end

Hope this helped :slight_smile:

@njesk12

Edited your code a bit.

I am getting a error

local folder = script.Parent
local _colors = {
	"Bright red",
	"Bright blue",
	"Bright yellow",
	"Bright purple",
	-- you can go on and insert more different BrickColors here...
}

while wait(2) do -- you can change the 5 to wait as many seconds as you want (this changes the colors every 5 seconds
	local children = folder:GetChildren()
	local randomPart = children[math.random(1,#children())] -- this chooses a random child from folder
	randomPart.BrickColor = BrickColor.new (_colors[math.random(1,#_colors)]) -- sets to random color
	if randomPart.BrickColor == BrickColor.new("Bright red") then
		randomPart.CanCollide = false
	else 
		randomPart.CanCollide = true
		
end

No idea what this means.

I’m assuming this is what you mean:
while true do part.BrickColor = BrickColor.Random wait(1) end if part.BrickColor = BrickColor.Red then part.CanCollide = false end

Understood, created it at the top of my head in Markdown but play around with it as it works for you!

Try mine:

Mine works, I think.

1 Like

Yep your works.

Thank You so much

Np!

If you need anymore help, you can message me on my Roblox profile.

Have a good day!

Oh no,

Theres 1 problem

It only changes 6 times I want it to be changing all the time.

local folder = script.Parent:GetChildren()
local RandomColors = {
	BrickColor.new('Really red'), 
	BrickColor.new("Really black"), 
	BrickColor.new("Really blue"), 
	BrickColor.new("Bright green"), 
	BrickColor.new("Bright yellow")
}
while wait(.5) do
	local RandomPart = folder[math.random(1, #folder)]
	local Color = RandomColors[math.random(1, #RandomColors)]
	RandomPart.BrickColor = Color
	if Color == BrickColor.new('Really red') then
		RandomPart.CanCollide = false
	else
		RandomPart.CanCollide = true
	end
end

Ok tested some more

It only changes colors for like 6 or so then stops than maybe makes one or 2 change

Alright tested even more.

It sometimes picked the script in the folder so it broke.

I moved it and now works fine.