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

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

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

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 comment

1

if team == BrickColor.new("Really blue") would also have worked.

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