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

How do I get the player's team?

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

✓ Accepted answer

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)

4 comments

0

I wanted to make it so that it gets the player's team's name but this works, thanks!

1

Just compare player.Team to the team in TeamService. Teams:FindFirstChild() is one method.

0

Learn something new everyday, thanks Xpol.

0

or just do player.Team.Name facepalm

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