Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you script a lightswitch to only let certain people turn on and off?

Asked by 11 years ago

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

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
11 years ago

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 ClickDetectorinto 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 MouseClickevent 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.

01click.MouseClick:connect(function(player_who_clicked)
02    if admins[player_who_clicked.Name:lower()] then
03        if light.Brightness > 0 then
04            light.Brightness = 0
05        else
06            light.Brightness  = 10
07        end
08    end
09end)
10-- Anonymous functions, like the one we used require a closed parenthesis to close the open parenthesis at the top.

Now, all together.

01local admins = { azarth = true,  elitegamingchicken = true, player1 = true}
02local light = script.Parent.SpotLight
03local click = script.Parent.ClickDetector
04 
05click.MouseClick:connect(function(player_who_clicked)
06    if admins[player_who_clicked.Name:lower()] then
07         -- :lower() makes the word all lowercase.
08        print(player_who_clicked.Name.. " is in the admins table!")
09        if light.Brightness > 0 then
10            print("Turn the light off")
11            light.Brightness = 0
12        else
13            print("Turn the light on")
14            light.Brightness  = 10
15        end
16    end
17end)
0
Hi im still struggling could you explain it a bit more detailed? EliteGamingChicken 15 — 11y
Ad

Answer this question