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

How can I make a door open and close only by one team?

Hi guys, I created a door that opens with a button that needs to be clicked with the mouse, but now I need this door to be opened and closed only by one team. How can I do?

This is the button code:

function onClicked()
	if script.Parent.Parent.Power.Value == true then
		if script.Parent.Parent.Valid.Value == true then
			script.Parent.Parent.Valid.Value = false
			if script.Parent.Parent.Active.Value == false then
				script.Parent.Parent.Active.Value = true
			elseif script.Parent.Parent.Active.Value == true then
				script.Parent.Parent.Active.Value = false
			end
		end
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

If you didn't know already, MouseClick passes a player argument when it fires. You can check what team that player is on when they click on the ClickDetector using the passed argument.

Example:

local function onClicked(player) -- Parameter for the player argument
	if player.Team == game:GetService("Teams"):FindFirstChild("Team Name") then
		print(player.Name, " has clicked on the supporting ClickDetector")
	end
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)

In the output, you should get this if you are on the team:

(player) has clicked on the supporting ClickDetector

More information here.

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