Problem with making a puzzle door

Hello as you can see I have a problem with making my puzzle door so here is the problem:

I made a script that two-button when you click on them they will change their color and when they both changed their colors the door becomes transparent and you can go through it but my script doesn’t work
here is the script:

while true do
	if script.Parent.red.BrickColor == "Bright orange" and script.Parent.Blue.BrickColor == "Bright blue" then
		print("pp")
		script.Parent.Part.Transparency = 1
		script.Parent.Part.CanCollide = false
	end
end

what is the problem?

1 Like

Try doing

if part.BrickColor == BrickColor.new("Cab yellow")

For example
You’re currently comparing a brick color to a string, so you have to convert the string to a brick color for comparison

1 Like

I tested that before and didn’t work

1 Like

Is this a normal script or local script?
Also are you changing the color in a normal script or local script?

1 Like

all of them are in normal script

1 Like

Try to change “while true do” to “while wait(1) do”. Maybe the script was running so fast it crashed or smth

1 Like

is better

while true do
wait() -- or task.wait()

the “while wait() do” isn’t recommended because it has a chance of don’t work.

1 Like

I haven’t heard anyone saying you shouldn’t use “while wait() do” but ok. Can you send the local script that you use to make the part change color?

1 Like

I just noticed that “red” and “Blue” have different capitalizations. Is this also how you set up your parts? Seems like an easy error to overlook.

2 Likes

Maybe try printing the brick colors in the while loop too
This could bring a lot of clarity to the issue

1 Like

won’t that print an error in the output? I am suspecting that they changed the color on the client-side so the server didn’t detect anything

1 Like

for the red button;

script.Parent.ClickDetector.MouseClick:Connect(function()

script.Parent.BrickColor = BrickColor.new("Bright orange")

end)

for the blue button:

script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Parent.BrickColor = BrickColor.new("Bright blue")
end)
1 Like

Yep exactly what I sus out. You must use a remote event and have the color changed on the server side so the server can detect this. If you change the color on a local script then it will only affect the client associated with the script.

1 Like

no, it doesn’t print anything in the output

You don’t have to use a RemoteEvent. You just have to change the LocalScript to a Script.

1 Like

I’m using normal script not local

1 Like

Replace the while true do with while wait() do, as while true do exhausts the script’s execution time.

1 Like

fixed it and it’s the result

while wait() do
	if script.Parent.red.BrickColor == BrickColor.new("Bright orange") and script.Parent.Blue.BrickColor == BrickColor.new("Bright blue") then
		script.Parent.Part.Transparency = 1
		script.Parent.Part.CanCollide = false
	end
end
1 Like

I personally can be staring at an error message and not see it. I would recommend adding an else debug statement:

while true do
	if script.Parent.red.BrickColor == "Bright orange" and script.Parent.Blue.BrickColor == "Bright blue" then
		print("pp")
		script.Parent.Part.Transparency = 1
		script.Parent.Part.CanCollide = false
	else
        print(script.Parent.red.BrickColor)
        print(script.Parent.Blue.BrickColor)
end
end

I think that would verify the problem.

1 Like

I have another question too:

How to disable while wait() do after it did the job?