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

How to turn on a light using a bricks transparency?

I'm completely new to coding, I wanted to know if it's possible to turn on a spotlight by having a brick opaque, and if so, how do I do it.

1 answer

✓ Accepted answer

Let's say the part's name is LightPart.

Do the following.

while true do 
if game.Workspace.LightPart.Transparency == 1 then
 -- Checks if it's Transparent.
game.Workspace.LightPart.SpotLight.Enabled = true 
-- If it is, it turns the SpotLight on.
wait(1) 
-- One secound before it checks again.
end

This will turn the SpotLight on if the part's Transparency is 1.

The while true do tells the game to always check if the part is transparent or not.

if game.Workspace.LightPart.Transparency == 1 then Is basically telling the game, "Is this Transparent or not?".

game.Workspace.LightPart.SpotLight.Enabled = true is changing the value Enabled (Turning it on.) to true.

wait(1) is how long it's going to wait before it checks again. In this script, it's 1 second.

end is the end of the while true do in the script.

I hope this helped you understand coding a bit more.

I highly advise taking a look at https://developer.roblox.com/. A lot of helpful information can be found there.

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