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

How do you make a clickable door and make it so only a certain player can open the door?

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)

1 answer

ClickDetector.MouseClick:Connect(function(player)
	for i, v in pairs (AllowedPlayers) do
		if player.UserId == AllowedPlayers[i] then
			-- Your event.
		end
	end
end)

3 comments

0

Can use this in a LocalScript if you wish to make the door visible to the player only.

0

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.

0

So i just add that code (first) above the click door code

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