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

How would I make it so that only a specific person can open this door?

Asked by 5 years ago
door = script.Parent;
locked = true

function setform(v)
locked = v
if v then
door.Transparency = 0
door.Reflectance = 0.4
door.CanCollide = true
else
door.Transparency = 0.7
door.Reflectance = 0
door.CanCollide = false
end

end


function click()
if locked then
setform(false)
wait(5)
setform(true)
end
end

door.ClickDetector.MouseClick:connect(click)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

GENERAL ISSUES

Please indent your code so it is easier to understand / find issues

You can place the function connection with its definition for the ClickDetector

connect is deprecated in favor of Connect

REVISIONS

local door = script.Parent
local locked = true

local function setform(v)
    locked = v
    if v == false then
        door.Transparency = 0
        door.Reflectance = 0.4
        door.CanCollide = true
    else
        door.Transparency = 0.7
        door.Reflectance = 0
        door.CanCollide = false
    end
end

door.ClickDetector.MouseClick:Connect(function(player)
    if locked then
        setform(false)
        wait(5)
        setform(true)
    end
end)

If you want the script to only appear to open to a single player, you will need to place the above code into a LocalScript since with FilteringEnabled, changes on the Client will not replicate to the Server.

If you only want a certain player (by team or name) to enter the door, you will need to add an additional clause where "if v then" is:

local door = script.Parent
local locked = true

local function setform(v, player)
    locked = v
    if v == false and player.Name == "UserNameHere" then
        door.Transparency = 0
        door.Reflectance = 0.4
        door.CanCollide = true
    else
        door.Transparency = 0.7
        door.Reflectance = 0
        door.CanCollide = false
    end
end

door.ClickDetector.MouseClick:Connect(function(player)
    if locked then
        setform(false, player)
        wait(5)
        setform(true, player)
    end
end)

The above example depicts the door only being opened by a person with the username "UserNameHere" while "v" is false.

EDIT: Forgot the last parentheses, but going back over this, you dont even need the first local function, here is a revision:

local door = script.Parent
local locked = true

door.ClickDetector.MouseClick:Connect(function(player)
    if locked == false then return end
    locked = false
    if player.Name == "GarrettlovesGTA" then
        door.Transparency = 0.7
        door.Reflectance = 0
        door.CanCollide = false
        wait(5)
        door.Transparency = 0
        door.Reflectance = 0.4
        door.CanCollide = true
    end
    locked = true
end)
0
It does not work. GarrettlovesGTA -1 — 5y
Ad

Answer this question