I have designed the light switch but now I need an example of a switch that will let me put in the light switch so it makes it so only people I allow in the script can toggle the switch on and off.
I have tried a few VIP door scripts but they do not work in light switches, could someone help me out and also tell me how I put the script into the lightswitch?
Thanks,
EliteGamingChicken
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.
click.MouseClick:connect(function(player_who_clicked) if admins[player_who_clicked.Name:lower()] then if light.Brightness > 0 then light.Brightness = 0 else light.Brightness = 10 end end end) -- Anonymous functions, like the one we used require a closed parenthesis to close the open parenthesis at the top.
Now, all together.
local admins = { azarth = true, elitegamingchicken = true, player1 = true} local light = script.Parent.SpotLight local click = script.Parent.ClickDetector click.MouseClick:connect(function(player_who_clicked) if admins[player_who_clicked.Name:lower()] then -- :lower() makes the word all lowercase. print(player_who_clicked.Name.. " is in the admins table!") if light.Brightness > 0 then print("Turn the light off") light.Brightness = 0 else print("Turn the light on") light.Brightness = 10 end end end)