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 10 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
10 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.

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) 
0
Hi im still struggling could you explain it a bit more detailed? EliteGamingChicken 15 — 10y
Ad

Answer this question