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

How do I check if a player is in a specific team?

Asked by 9 years ago

Here's what I've got so far, but it just doesn't work. According to the Print()'s I used, it should work. Can anyone tell me what I'm doing wrong here?

if _G.Block.LastCharacter then
    print(_G.Block.LastCharacter) -- Prints 'Player1' (character)
    local team = game.Players:GetPlayerFromCharacter(_G.Block.LastCharacter).TeamColor
    print(team) -- Prints 'Really blue'
    if team == "Really blue" then print("Found") end -- Still nothing
end

1 answer

Log in to vote
1
Answered by 9 years ago

Alright, it turned out to be a mistake I made when trying to compare. TeamColor uses the BrickColor data type. So I have to use the Name property to make it run properly.

if _G.Block.LastCharacter then
    print(_G.Block.LastCharacter) -- Prints 'Player1' (character)
    local team = game.Players:GetPlayerFromCharacter(_G.Block.LastCharacter).TeamColor
    print(team) -- Prints 'Really blue'
    if team.Name == "Really blue" then print("hit") end
end
1
if team == BrickColor.new("Really blue") would also have worked. adark 5487 — 9y
Ad

Answer this question