How do I change the color of ALL blocks with the same name?

I’m developing a game and I was planning to do a blackout and the part I didn’t know how to do was change the color from white to black as if they were off. I tried to look elsewhere for help but it didn’t work, so I came here.

My script here:

llocal teamM = game.Teams["Afternation inc"]
local teamM = game.Teams["Cívis"]
local ProximityPromptService = game:GetService("ProximityPromptService")

local LiBool = script.Parent.Parent.Parent.Parent.Parent.Lights

local Gene2 = script.Parent.Parent.Parent.Parent.Big
local Gene = script.Parent.Parent.Parent.Parent.Gene
local Promp = script.Parent.Parent.ProximityPrompt
local SemPromp = script.Parent.Parent
local BombPro = script.Parent.Parent.Parent.Bomb
local Bomb = script.Parent.Parent.Parent.BombExplosive
local Light1 = script.Parent.Parent.Parent.BombExplosive.PointLight
local Smoke = script.Parent.Parent.Parent.BombExplosive.Smoke
local Sound = script.Parent.Parent.Parent.BombExplosive.Sound
local SoundExplo = script.Parent.Parent.Parent.BombExplosive.SoundExplosion
local Proxi = script.Parent.Parent.ProximityPrompt




script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(player)
	if player.Team == teamM then
		Promp.Enabled = false
		Bomb.Transparency = 0
		Bomb.CanCollide = true
		BombPro.Transparency = 1
		Sound:Play()
		Light1.Enabled = true
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --1
		Light1.Enabled = true
		wait(0.5) --1,5
		Light1.Enabled = false
		wait(0.5) --2
		Light1.Enabled = true
		wait(0.5) 
		Light1.Enabled = false
		wait(0.5) --3
		Light1.Enabled = true
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --4
		Light1.Enabled = true
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --5
		Light1.Enabled = true
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --6
		Light1.Enabled = true
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --7
		Light1.Enabled = true 
		wait(0.5)
		Light1.Enabled = false
		wait(0.5) --8
		Light1.Enabled = true
		wait(0.5) ---0,5
		Smoke.Enabled = true
		wait(0.5) --1
		wait(0.5) --1,5
		wait(0.5) --2
		Light1.Enabled = false
		SoundExplo:Play()
		Bomb.CanCollide = false
		Bomb.Transparency = 1
		wait(3)
		Smoke.Enabled = false
		Gene.Material = Enum.Material.CorrodedMetal
		Gene2.Material = Enum.Material.CorrodedMetal
		LiBool.Value = true
	end
end)

for i,brick in ipairs(workspace:GetChildren()) do
	if brick:IsA("Part") and brick.Name == "Light" then
		SemPromp.ProximityPrompt.Triggered(function(obj)
			if LiBool.Value == true then
				brick.BrickColor = BrickColor.new("Black")
			end
		end)
	end
end
1 Like

I suggest you to have all the parts you want to color in a folder inside workspace. You can add more checks depending on your needs.

for a,b in pairs(game.Workspace.Folder:GetChildren()) do
if b.Name == "part name" then
b.Color = Color3.fromRGB(0,0,0)
end

as simple as a for loop. If you need help on this, reply to this.

Two of your variables share the name teamM May not be the answer you’re looking for, but it can cause problems.

How would you do this so that the color of the blocks would change to another color?

First, put your parts into a model.

for i,v in pairs(PartModel:GetChildren()) do
v.Color = Color3.new(yourcolor)
end

There you go, easy as that.

1 Like

And if I put it like this?

local LightModel = workspace.LightModel

for i,v in pairs(LightModel:GetChildren()) do
	if LiBool.Value == true then
		v.Color = Color3.new(0, 0, 0)
	end
end

Because I wish someone had to press it and then everyone would turn it black so I made that if the bool was true then that would happen.

I would add LiBool.Changed:Connect(function() and then run the if statements.

If you need more checks, add else or elseif.

local LightModel = workspace.LightModel

for i,v in pairs(LightModel:GetChildren()) do
	LiBool.Changed:Connect(function()
	if LiBool.Value == true then
		v.Color = Color3.new(0, 0, 0)
	   end
    end)
end
1 Like

The first word has a spelling mistake. local not llocal

1 Like

It’s an error that I accidentally put on the page, in the studio I don’t have this error. But thanks for saying.

1 Like

Alright No spoiler. Just me wasting time because Roblox doesn’t allow less than 30 damn characters or something like that. UGHHH. ROBLOX PLEASE CHANGE THIS!

That worked, thanks. But I have a doubt, can I do the same for the lights stuff? (Spotlight)

Yes, that would work too. Have a nice day!

You too.

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Word Limit ^