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)
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.