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
function bedlight()
    local state = script.Parent.Parent.Parent.State
    local switch = script.Parent.Parent.Parent
    local lamp = script.Parent.PointLight
    if state.Value == false then
        state.Value = true
        lamp.Enabled = true
    else
        state.Value = false
        lamp.Enabled = false
    end
end

script.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
function bedlight()
-- check if state, switch, and lamp exsist
    local state = script.Parent.Parent.Parent.State

    local switch = script.Parent.Parent.Parent

    local lamp = script.Parent.PointLight

    if state.Value == false then

        state.Value = true

        lamp.Enabled = true

    else -- change this to 'elseif state.Value == true then'
        state.Value = false

        lamp.Enabled = false

    end

end


-- Check to make sure that 'script.Parent.Parent.Parent.ClickDetector exist

script.Parent.Parent.Parent.ClickDetector.MouseClick:connect(bedlight)
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