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

How do I get the player's team?

Asked by 5 years ago

I wanted to make a system that only people from a certain team can execute a function.

Here's what I have (It doesn't work and no error message shows up in the output):

local UIS = game:GetService("UserInputService")
local players = game:GetService("Players")

local player = players.LocalPlayer

local function getKey(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode

        if keyPressed == Enum.KeyCode.E then
            print("The player pressed E!")

            if player.Team == "Killer" then
                print("The player is a killer!")
            end
        end
    end
end

UIS.InputBegan:Connect(getKey)

1 answer

Log in to vote
0
Answered by 5 years ago

Use BrickColor/TeamColor to get the team a player is on.

local UIS = game:GetService("UserInputService")
local players = game:GetService("Players")

local player = players.LocalPlayer

local function getKey(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode

        if keyPressed == Enum.KeyCode.E then
            print("The player pressed E!")

            if player.TeamColor == BrickColor.new("Bright red") then
                print("The player is a killer!")
            end
        end
    end
end

UIS.InputBegan:Connect(getKey)
0
I wanted to make it so that it gets the player's team's name but this works, thanks! arthurdaniel91 72 — 5y
1
Just compare player.Team to the team in TeamService. Teams:FindFirstChild() is one method. xPolarium 1388 — 5y
0
Learn something new everyday, thanks Xpol. DinozCreates 1070 — 5y
0
or just do player.Team.Name *facepalm* Gey4Jesus69 2705 — 5y
Ad

Answer this question