Insert the Script
into the brick from the BasicObjects menu in studio
Insert your SpotLight
into the brick from the BasicObjects menu in studio
Insert a ClickDetector
into the brick from the BasicObjects menu in studio
** View > Basic Objects, if you can't see the menu**
Make a table
for our admins list.
local admins = { azarth = true, elitegamingchicken = true, player1 = true}
I like using dictionaries, since you don't have to loop through them to find a name.
Direct your variable to the ClickDetector and another to the light
local click = script.Parent.ClickDetector
local light = script.Parent.SpotLight
Use the MouseClick
event to detect clicks. This event returns the player who clicked it, so we can use that to check if they're in our admins table.
01 | click.MouseClick:connect( function (player_who_clicked) |
02 | if admins [ player_who_clicked.Name:lower() ] then |
03 | if light.Brightness > 0 then |
Now, all together.
01 | local admins = { azarth = true , elitegamingchicken = true , player 1 = true } |
02 | local light = script.Parent.SpotLight |
03 | local click = script.Parent.ClickDetector |
05 | click.MouseClick:connect( function (player_who_clicked) |
06 | if admins [ player_who_clicked.Name:lower() ] then |
08 | print (player_who_clicked.Name.. " is in the admins table!" ) |
09 | if light.Brightness > 0 then |
10 | print ( "Turn the light off" ) |
13 | print ( "Turn the light on" ) |