Hello, I'm new to this site and Lua. Okay, lets cut to the chase.
01 | MyPart = script.Parent |
02 |
03 |
04 | function ColorClick () |
05 | MyPart.BrickColor = BrickColor.new( "Lime green" ) |
06 | end |
07 |
08 | MyPart.ClickDetector.MouseClick:connect(ColorClick) |
09 |
10 | if MyPart = = "Lime green" then |
11 | function ColorClickTwo () |
12 | MyPart.BrickColor = BrickColor.new( "Really red" ) |
13 |
14 | end |
15 | end |
16 |
17 | MyPart.ClickDetector.MouseClick:connect(ColorClickTwo) |
I am trying to change a red brick to green by clicking it, which works, but now i'm trying to change it back to red by clicking it again. So, i'm basically trying to change the brick color back and forth by clicking it. When I test it, I would click the red brick, and it would turn green. But, when I click it again, it doesn't do anything, and it would say in the output, "attempt to call a nil value".
Sorry if this is a dumb question, but I am new to Lua, and really can't figure this out.
First off, Welcome to Scripting Helpers. Here is some of the main problems I found. I've realized my first answer didn't work, here is an alternative. This will work like so. If you hover over the part, it will turn green. Once your stop hovering, it will turn red. When you click, in the output will show that is was clicked.
01 | --// Functions |
02 | function HoverOn(Enter) -- Calls on HoverOn |
03 | script.Parent.BrickColor = BrickColor.new( "Lime green" ) |
04 | end |
05 |
06 | function HoverOff(Leave) -- Calls on HoverOff |
07 | script.Parent.BrickColor = BrickColor.new( "Really red" ) |
08 | end |
09 |
10 | function Click(Click) -- Calls on Click |
11 | print (script.Parent.Name.. " was clicked." ) |
12 | end |
13 |
14 | --// CallBacks |
15 | script.Parent.ClickDetector.MouseHoverEnter:connect(HoverOn) |
16 | script.Parent.ClickDetector.MouseHoverLeave:connect(HoverOff) |
17 | script.Parent.ClickDetector.MouseClick:connect(Click) |
Wish you the best of luck in your journey.