Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

0
Please show us what is inside BuzzerOne, BuzzerTwo and BuzzerThree. gskw 1046 — 10y
0
Nothing. Just parts WelpNathan 307 — 10y

3 answers

Log in to vote
1
Answered by
gskw 1046 Moderation Voter
10 years ago

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.

0
Worked perfectly thanks! :) WelpNathan 307 — 10y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
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 WelpNathan 307 — 10y
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. BlueTaslem 18071 — 10y
0
Ahh. Okay. Anyway you helped me too :) Because I needed this for another thingy mabob haha.Thanks :) WelpNathan 307 — 10y
Log in to vote
0
Answered by 10 years ago

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

Answer this question