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

How to make a light switch that powers my lamp?

Hello, I'm trying to create a lamp that is powered by a light switch. The only thing I need will be the light switch and someway to turn on the lamp with it.

Example: Once pressed on the "Light switch" light turns on in the room.

Really short explanation and I'm sorry if it's not enough for you, and I hope that it's understandable! Any help would be appreciated!

2 comments

0

Add a ClickDetector in the light switch

0

That is exactly what I did before you commented this, but I need to connect the light switch to the lamp somehow.

1 answer

As was suggested, the easiest approach would be to use a click detector. A click detector has an event called MouseClick which fires when a player clicks on the click detector's parent part.

So with that in mind here's an example script

local switchClickDetector = game.Workspace.LightSwitch.ClickDetector
local lampLight = game.Workspace.Lamp.PointLight

switchClickDetector.MouseClick:Connect(function(player)
	lampLight.Enabled = not lampLight.Enabled -- flip the value from whatever it was
end)

1 comment

0

Thank you!

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