How to make a team-only button?

I need a button for a border game in the admission booth to open a door, the problem is that any player can zoom out and press it to open then door. That’s when I realized I needed a button that will only work if a player on a certain team (in this case “admission”) pressed it. I have contacted multiple friends and tryed multiple scripts myself but unfortunately, nothing works.

This is my script: https://gyazo.com/fe18242fe5d10aad35fd69cb590fcfe0

It will be greatly appreciated if someone could help me out. Thanks :)!

4 Likes

You never called the function when it is actually clicked

If you are using a ClickDetector, it will return the player who clicks it as an argument, so click will be the player. And on normal script, you can’t do game.Players.LocalPlayer.

2 Likes

Your parameter, click inside the function is automatically going to be the player. You do not need to and cannot call game.Players.LocalPlayer from a server-sided script.

Therefore, saying click.Parent is going to refer to the folder game.Players, as it is where the player is kept. I have included an example below on how to go about this.

local group = script.Parent.Parent.Parent

function onClick(click)
    if click.TeamColor == BrickColor.new("Bright green") then
        group.Parent.Door.Door.Transparency = 1
        group.Parent.Door.Door.CanCollide = false
        print("Player is on team!")
    else
        print("Player is not on team!"
    end
end

script.Parent.MouseClick:Connect(onClick) 
4 Likes

Alright, Thanks everyone! (This is my first time posting in dev forum btw)

1 Like

Please embed code, it makes it easier to read. To do so put three backticks (```) and then paste the code. After that put three more backticks to end the code block.

Alright, thanks for the help! 30 Chars

Tysm, I was looking for this script for so long. :grinning: :grinning: :grinning: :100:

1 Like