Ad
Log in to vote
0

On/Off Button Lantern?

Asked by 6 years ago

I need help with this. I tinkered around with a free model (mainly for learning how coding works) and it isn't working. What is wrong here?

mylight = game.Workspace.Lamp.Lamp.ButtonLight.PointLight
function click()
    mylight.Enabled = not mylight.Enabled
end

Anyways, the output suggests putting a '=' sign by Function. Its not working. the 2nd line is the only problem. This is for a lantern with a clickable on/off button.

2 answers

Log in to vote
0
Answered by
KarlXYZ 120
6 years ago

This probably isn't the most efficient way to deal with your issue, but it should still work fine.

Just replace this with your current function.

function click()
    if mylight.Enabled == true then
        mylight.Enabled = false
    else if mylight.Enabled == false then
        mylight.Enabled = true
    end
    end
end
Ad
Log in to vote
0
Answered by 6 years ago

Exactly as above, except that you need to add the following:

--Edit ButtonPathHere with the path leading to your on/off button.
ButtonPathHere.MouseButton1Click:connect(click)

Answer this question