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

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

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

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) 

1 comment

0

Hi im still struggling could you explain it a bit more detailed?

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