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

How would YOU write a script for a lightswitch to only toggle when authorised people do it?

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

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

1 answer

Log in to vote
0
Answered by 11 years ago

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:

01local player = game.Players.LocalPlayer
02local isAuthorized = false
03function togglePlayerAuth()
04    if not isAuthorized then
05        isAuthorized = true
06    else
07        isAuthorized = false
08    end
09end
10 
11game.Workspace.YourLightswitch.MouseClick:connect(function(p)
12    if not isAuthorized then
13        -- Your code
14    else
15        -- Your code
16    end
17end)

Script Way You can declare a BoolValue called "isAuthorized" this too, same way of the LocalScript way.

01function onPlayerLogin(p)
02    local tempdata = p:FindFirstChild("TempData")
03    if not tempdata then
04        tempdata = Instance.new("Model", p)
05        tempdata.Name = "TempData"
06    else
07        local isAuthorized = tempdata:FindFirstChild("IsAuthorized")
08        if not isAuthorized then
09            isAuthorized = Instance.new("BoolValue", tempdata)
10            isAuthorized.Name = "IsAuthorized"
11            isAuthorized.Value = false
12        end
13    end
14end
15 
View all 37 lines...

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!

Ad

Answer this question