Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"If's and and's" Help please? [SOLVED]

Hello, please may I have some help with this script please? I have no idea why it isn't working...

Please help me correct this please! Thanks.

BuzzerOne=game.Workspace.Buzzers.BuzzerOne
BuzzerTwo=game.Workspace.Buzzers.BuzzerTwo
BuzzerThree=game.Workspace.Buzzers.BuzzerThree
Intro=game.Workspace.Intro

function onClick()
	if BuzzerOne.BrickColor.Red() and BuzzerTwo.BrickColor.Red() and BuzzerThree.BrickColor.Red() then
		Intro:Play()
	end
end


script.Parent.ClickDetector.MouseClick:connect(onClick)

16:53:37.142 - BrickColor is not a valid member of Model 16:53:37.143 - Script 'Workspace.Part.Script', Line 7

3 comments

0

Please show us what is inside BuzzerOne, BuzzerTwo and BuzzerThree.

0

Nothing. Just parts

3 answers

✓ Accepted answer

Correction

BuzzerOne=game.Workspace.Buzzers.BuzzerOne
BuzzerTwo=game.Workspace.Buzzers.BuzzerTwo
BuzzerThree=game.Workspace.Buzzers.BuzzerThree
Buzzers = {BuzzerOne,BuzzerTwo,BuzzerThree}
Intro=game.Workspace.Intro

function onClick()
	local isvalid = true
	for _,v in pairs(Buzzers) do
		for _,w in pairs(v:GetChildren()) do
			if w.BrickColor ~= BrickColor.Red() then
				isvalid = false
			end
		end
	end
    if isvalid then
        Intro:Play()
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

Explanation

There were parts inside the models. Those are what you have to test the BrickColor on, not the model itself as it has no BrickColor on it.

1 comment

0

Worked perfectly thanks! :)

As the error says,

BuzzerOne (or ..Two or ..Three, I don't know which; but probably all of them) is a Model. Models don't have BrickColor properties, which is your error. Make BuzzerOne refer to a part rather than a model.


If it were a part, your code still wouldn't work. You have to compare the values, not just call .Red() on them. Comparison for equality is done with the == operator (read "is equal to"). It is unrelated to the assignment construct =.

if BuzzerOne.BrickColor == BrickColor.Red() and BuzzerTwo.BrickColor == BrickColor.Red() and BuzzerThree.BrickColor == BrickColor.Red() then

3 comments

0

It is still giving me a error ;( 17:04:58.560 - BrickColor is not a valid member of Model 17:04:58.561 - Script 'Workspace.Part.Script', Line 7

0

You didn't change it then. The accepted answer works because it is fixing it for you by using a much more complicated solution.

0

Ahh. Okay. Anyway you helped me too :) Because I needed this for another thingy mabob haha.Thanks :)

This is just to test with to show that it works this script works with a normal brick, I used name but you could use other. hope this helps

while true do
	if script.Parent.BrickColor.Name == "Bright red" then
		print("ok")
	end
	wait(5)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.