I would like to know how to make a clickable door and make it so only a certain player can open it, i have the code to make a clickable door and to make it so a certain player id can open it but i dont know how to join the codes together, does anyone know how to help?
All i need help with is joining the codes, if anyone could help that would be great!
Clickable door code
local Wood = true
local parent = script.Parent
local function on()
Wood = true
parent.Transparency = 0
parent.CanCollide = true
end
local function off()
Wood = false
parent.Transparency = 0.8
parent.CanCollide = false
end
local function OnClicked()
if Wood == true then off() else on() end
end
parent.ClickDetector.MouseClick:connect(OnClicked)
on()
** Certain Player Code**
local AllowedPlayers = {39922681, 1} -- Add whoever you want to be able to click the ClickDetector (user id)
script.Parent.MouseClick:Connect(function(Player)
local FoundInTable = false
for _, userid in pairs(AllowedPlayers) do
if Player.UserId == userid and FoundInTable == false then
FoundInTable = true
end
end
if FoundInTable == true then
-- Player found in table, open door
else
-- Player wasn't found in table, show an error gui (preferably, you should fire a remote event to the player, and handle the gui effects on the client)
end
end)

3 comments
Can use this in a LocalScript if you wish to make the door visible to the player only.
I will answer instead of him. Local scripts run any code on the player's client, so yes, use a local script and only the player will see.
So i just add that code (first) above the click door code