Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can't click my brick with ClickDetector?

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

✓ Accepted answer
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)

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.