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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question