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

Help with scripting a light?

Hi,

I want to make a button that does two jobs. I press is once and it turns on the light, I press it again and it turns it off.

I have a blank script in the button with a click detector in the button as well.

This is the link from the script to the light

script.Parent.Parent.SpotLight1.Light.SpotLight

What would the script be so I can turn it on and off with the one button!?

Thanks Kieran

3 answers

✓ Accepted answer

easy... say this is the Light Model;

Light Model<

LightModel<< -LightPart --PointLight

ButtonModel<< -Button --ClickDetector -Script

LP = script.Parent.Parent.LightModel.LightPart.PointLight
btn = script.Parent.Button.ClickDetector

function onClick()
if LP.Enabled == true then
LP.Enabled = false
else
LP.Enabled = true

btn.MouseClick:connect(onClick)

6 comments

0

I have used this script with my in put into this, what am I doing wrong?

0

LP = script.Parent.Parent.SpotLight1.Light.PointLight btn = script.Parent.ClickDetector function onClick() if LP.Enabled == true then LP.Enabled = false else LP.Enabled = true btn.MouseClick1:connect(onClick) end end

0

lemme see... well 1st try see if there are any red lines (errors) then check the output...

0

Nope, there arn't any

0

It's ok now I have managed to configure it. Thanks

0

np, sry I couldn't respond to help faster though...

LP = script.Parent.Parent.SpotLight1.Light.PointLight
btn = script.Parent.ClickDetector

function onClick()
if LP.Enabled == true then
LP.Enabled = false
else
LP.Enabled = true

btn.MouseClick1:connect(onClick)

end
end

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