Brick color not changing

I’m trying to set the brick colour but it’s not changing it.

game.Workspace.ClickEventOff.OnServerEvent:Connect(function()
	game.Workspace.Screens.l1.BrickColor = BrickColor.new("Really black")
	game.Workspace.Screens.l2.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l3.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l4.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l5.BrickColor = BrickColor.new("Really Black")

end)

it ok! you no need to use RemoteEvent to change brickcolor! you can use ClickDetector.MouseClick!

its like this!

game.Workspace.Off.ClickDetector:Connect(function()
	game.Workspace.Screens.l1.BrickColor = BrickColor.new("Really black")
	game.Workspace.Screens.l2.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l3.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l4.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l5.BrickColor = BrickColor.new("Really Black")

end)
1 Like

Error: Connect is not a valid member of ClickDetector "Workspace.Off.ClickDetector"

local part = script.Parent

part.MouseButton1Click:Connect(function()
        game.Workspace.Screens.l1.BrickColor = BrickColor.new("Really black")
	game.Workspace.Screens.l2.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l3.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l4.BrickColor = BrickColor.new("Really Black")
	game.Workspace.Screens.l5.BrickColor = BrickColor.new("Really Black")

end)

There should be an event like

ClickDetector.MouseClick:Connect(function()

end)

Maybe this’ll help
(Not mean to be copy and pasted, meant to give the idea and help, tho u could probably copy and paste it)

-- Objects
local folderScreens = workspace.Screens
local off = workspace.Off
local clickDetector = off.ClickDetector

-- Values
local Color_To_Change_To = BrickColor.new("Really Black")

-- Functions
local function ChangeColor()
    for Index, Object in pairs(folderScreens:GetChildren()) do
        if Object:IsA("BasePart") then
            Object.BrickColor = Color_To_Change_To
        end
    end
end

-- Connections
clickDetector.MouseClick:Connect(ChangeColor)

Sorry if there’s any typos, it’s 4AM where I live, hopefully this helps

Some little bits of advice:

  • You don’t have to do game.Workspace, workspace is already there fore you to use!
  • I assume it was for an example but iterating through parts is much better than setting them all individually! (And easier!!!)
  • Declaring and referencing variables is a better practice and use of a computer’s resources than calling something like game.Workspace.Screens every time

I don’t understand why is this script not working, because I took this from my older project and there it works

If you can’t figure out the problem try slapping some print functions down until you can find where the code stops working

Edit: The problem could be that your remote isn’t actually firing to the server

I found the issue. I had a Random Local Script in StarterGUI (in the Old Project where I took this feature) that looks like this:

local PressEvent = game.Workspace.On.ClickDetector
PressEvent.MouseClick:Connect(function()
	game.Workspace.ClickEventOn:FireServer()
end)

local PressEvent = game.Workspace.Off.ClickDetector
PressEvent.MouseClick:Connect(function()
	game.Workspace.ClickEventOff:FireServer()
end)

But thank you for helping and I will keep your tips in mind!

1 Like

Hello I just want to add something it will make your code a lil bit cleaner

It can be something like this

for _,part in pairs (game.Workspace.Screens:GetChildren()) do

if part:IsA("BasePart") then
      part.BrickColor = BrickColor.new("Really Black")
end

end)

It isn’t really necessary but it can help reduce the time to type it out and imo it looks much more cleaner

Sorry if there’s any syntax errors and it lacks spaces, I just wrote it on my phone so it looks bad

EDIT: oops @bearturnedhuman already sent out a code similar to mine

1 Like

Try change brickcolor without script
Hope this works!