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

What is wrong with my on/off button test I made for my game?

Asked by 4 years ago

I'm trying to make an on/off object with only one button. I've made a little test which does the following: - The first time you click it, it changes the brickcolor of a part called ''on''. Then it changes the color of the button itself.

  • The second time you click it, it's supposed to change the brickcolor of a part called ''off''.

I've made this little test to understand how to script an on/off button. But It won't work.

Here's my script.

01if
02    script.Parent.Parent.testbutton.BrickColor = Color3(255, 0, 0)
03    then
04        script.Parent.ClickDetector.MouseClick:Connect(function()
05            script.Parent.Parent.on.BrickColor = Color3.new(0, 255, 255)
06            script.Parent.Parent.testbutton.BrickColor = Color3.new(0, 255, 0)
07            elseif
08                script.Parent.Parent.testbutton.BrickColor = Color3(0, 255, 0)
09                then
10                    script.Parent.Parent.off.BrickColor = Color3.new(0, 255, 255)
11                end
12        end)
13    end

On = Part 1 Off = Part 2

I would really like some help! Thank you in advance.

0
You're not using the comparison operand ==. You also cannot nest an elseif, it must remain within the conditional clause. Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I formated your code a bit. But I'm not sure it will run. Try it

01if script.Parent.Parent.testbutton.BrickColor == Color3(255, 0, 0) then
02        script.Parent.ClickDetector.MouseClick:Connect(function()
03            script.Parent.Parent.on.BrickColor = Color3.new(0, 255, 255)
04            script.Parent.Parent.testbutton.BrickColor = Color3.new(0, 255, 0)
05    end)
06 
07elseif script.Parent.Parent.testbutton.BrickColor == Color3(0, 255, 0) then
08    script.Parent.Parent.off.BrickColor = Color3.new(0, 255, 255)
09 
10end
Ad

Answer this question