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

I can't click my brick with ClickDetector?

Asked by
nanaluk01 247 Moderation Voter
9 years ago
01function bedlight()
02    local state = script.Parent.Parent.Parent.State
03    local switch = script.Parent.Parent.Parent
04    local lamp = script.Parent.PointLight
05    if state.Value == false then
06        state.Value = true
07        lamp.Enabled = true
08    else
09        state.Value = false
10        lamp.Enabled = false
11    end
12end
13 
14script.Parent.Parent.Parent.ClickDetector.MouseClick:connect(bedlight)

When I click try to click the switch in-game, it won't let me! Please help if you can. Thanks in advance.

3 answers

Log in to vote
0
Answered by 9 years ago
01function bedlight()
02-- check if state, switch, and lamp exsist
03    local state = script.Parent.Parent.Parent.State
04 
05    local switch = script.Parent.Parent.Parent
06 
07    local lamp = script.Parent.PointLight
08 
09    if state.Value == false then
10 
11        state.Value = true
12 
13        lamp.Enabled = true
14 
15    else -- change this to 'elseif state.Value == true then'
View all 27 lines...
Ad
Log in to vote
0
Answered by
Marios2 360 Moderation Voter
9 years ago

Ahmed here did a good try, but he only told you what to do and, just maybe, doesn't know you don't know how to do that.

So, here are the facts:

-You need not check for everything whether or not it exists. -If you are checking a boolean's value, you need not use an elseif statement. Why? Because a boolean is either true or false. If it is not false, it can only be true. And the opposite goes. -The "switch" variable is completely useless, because it is never used in the script after it is created.

I conclude that you made a mistake on the variables - you may be targeting the wrong objects, and is an issue which you can only fix at your own side. The script works fine otherwise. So all you need to do is remove the switch variable and fix the other variables.

Log in to vote
-1
Answered by
ImfaoXD 158
9 years ago

Hey, bro! I'll help you out. Here's the link to the model. I hope this helps. :)

Link: http://www.roblox.com/Light-Script-with-button-item?id=150896882

or

Link: http://www.roblox.com/unnamed-item?id=313474334

Answer this question