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
PS: Please include detailed instructions and tell me what part of the lightswitch does it go in, Cos i am using an normal ROBLOX stamper lightswitch
LocalScript Way
You can declare a boolean variable called isAuthorized
and change it in one of your custom function, and then use a conditional statement that checks if the player is authorized to use the lightswitch, something like this:
local player = game.Players.LocalPlayer local isAuthorized = false function togglePlayerAuth() if not isAuthorized then isAuthorized = true else isAuthorized = false end end game.Workspace.YourLightswitch.MouseClick:connect(function(p) if not isAuthorized then -- Your code else -- Your code end end)
Script Way You can declare a BoolValue called "isAuthorized" this too, same way of the LocalScript way.
function onPlayerLogin(p) local tempdata = p:FindFirstChild("TempData") if not tempdata then tempdata = Instance.new("Model", p) tempdata.Name = "TempData" else local isAuthorized = tempdata:FindFirstChild("IsAuthorized") if not isAuthorized then isAuthorized = Instance.new("BoolValue", tempdata) isAuthorized.Name = "IsAuthorized" isAuthorized.Value = false end end end function togglePlayerAuth(player) player:WaitForChild("TempData") local tempdata = player:FindFirstChild("TempData") local isAuthorized = player:FindFirstChild("IsAuthorized") if isAuthorized.Value == false then isAuthorized.Value = true else isAuthorized.Value = false end end game.Workspace.YourLightswitch.MouseClick:connect(function(p) local tempdata = p:FindFirstChild("TempData") local isAuthorized = tempdata:FindFirstChild("IsAuthorized") if isAuthorized.Value == false then -- Your code else -- Your code end end game.Players.PlayerAdded:connect(onPlayerLogin)
WARNING: Be aware when selecting from LocalScript or Script, if you use LocalScript then the code will execute on the CURRENT PLAYER RUNNING THE SCRIPT; If you instead of the LocalScript you decide to use the Script (the normal one) then this code will run on EACH PLAYER CALLED FROM THE FUNCTION!