Help with Brickcolor on Touch

Heya, I need help with the script, I’m trying to script a part that, after touching, Brickcolor changes, I tried to find it on ytb, but it didn’t move, you don’t know what’s wrong with it?

local cervena1 = game.Workspace.d1

local cervena2 = game.Workspace.d3

local con = script.Parent


local function onTouch()
	cervena1.BrickColor = BrickColor.new(76, 255, 62)
	wait(3)
	cervena1.BrickColor = BrickColor.new(250, 0, 0)
	
end

cervena1.Touched:Connect(onTouch)

Try the following and see how it works.

local cervena1 = game.Workspace.d1
local cervena2 = game.Workspace.d3
local con = script.Parent

local debounce = false
local function onTouch()
	if not debounce then
		debounce = true
		
		cervena1.Color = Color3.fromRGB(76, 255, 62)
		task.wait(3)
		cervena1.Color = Color3.fromRGB(250, 0, 0)
		
		debounce = false
	end
end

cervena1.Touched:Connect(onTouch)

add a ready/debounce, and use strings in the parameters of brickColor. Also use task library

I’m sorry, but it didn’t work, the problem still persists

What was the error? could you post please.

what type of script is it maybe that can be the problem

1 Like

If you mean in the console, there is no error

have you tried debugging, like adding print statements and stuff to check that the function is actually running

Is this a LocalScript or a server script? Your script works perfectly fine when I use it, so my presumption is that you’re using a LocalScript in workspace (localscripts don’t run in workspace unless parented to a player’s character)

1 Like

I have a script (Classic Script) in workspace

Can you take a screenshot of your explorer, making sure the parts and the script are in the screenshot?

1 Like

That one error is from other script

I meant screenshot where the script is in the explorer

You are putting numbers in BrickColor.new() like Color3.fromRGB() you’re supposed to put the BrickColor name not a Color3, like BrickColor.new("Bright blue")
try doing this:

local cervena1 = game.Workspace.d1

local cervena2 = game.Workspace.d3

local con = script.Parent


local function onTouch()
	cervena1.Color = Color3.fromRGB(76, 255, 62)
	wait(3)
	cervena1.Color = Color3.fromRGB(250, 0, 0)
	
end

cervena1.Touched:Connect(onTouch)

You sure ur using the right part? try using this code

local colorChangePart = script.Parent

local debounce = false
local function onTouch()
	if not debounce then
		debounce = true
		
		colorChangePart.Color = Color3.fromRGB(76, 255, 62)
		task.wait(3)
		colorChangePart.Color = Color3.fromRGB(250, 0, 0)
		
		debounce = false
	end
end

colorChangePart.Touched:Connect(onTouch)

Thak you so much, but i still have a problem, when i try to change the location in local, it will don!'t work

local cervena1 = game.Workspace.d1
local cervena2 = game.Workspace.d3
local con = script.Parent

local function onTouch()
	cervena1.Color = Color3.fromRGB(76, 255, 62)
	task.wait(3)
	cervena1.Color = Color3.fromRGB(250, 0, 0)
end

cervena1.Touched:Connect(onTouch)

The problem was you were changing the BrickColor using an RGB component. More details can be found here: Color3 | BrickColor

I do notice you were having problems changing some things local, would you elaborate?

It works!
Thanks a lot, can I ask you one more question?
What do I have to do if I want the part to change after I touch another part?

Could you possibly elaborate on “party”? Please answer these questions so I can help you further:

  • What is party?
  • What should it do?
  • What do you need it to do?
  • Where is it located?