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

How to I access the Player's Team?

The code I'm trying to do requires that the player's team is accessed through the chat, from the team color. However, I don't think that it's actually accessing the TeamColor. Any thoughts?

function onChatted(msg, recipient, speaker) 

local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 

	if msg == "test" and speaker.TeamColor == BrickColor.new("Mulberry") then
end 

end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

2 comments

0

I'm going to look into this :)

0

thanks :))

1 answer

✓ Accepted answer

Don't worry, I tested this script, and it works!

Here's some things I would change with the script:

  • The formatting, it's really hard to understand what was going on in the script.

  • Using more variables [Maybe even tables] for the exact message type and team color would be nice

Example of an Improved script:

local message = "test"
local teamColor = BrickColor.new("Mulberry")

function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	if msg == message and speaker.TeamColor == teamColor then
		print("Met the requirements, Yay")
	else
		print("Did not meet the requirements")
	end 
end 

function onPlayerEntered(newPlayer)
	print("Played joined") 
	newPlayer.Chatted:connect(function(msg, recipient)
		print("Player chatted")
		 onChatted(msg, recipient, newPlayer) 
	end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

TeamColor isn't really the best method for checking a player's team, I'd suggest just checking the actual team.

2 comments

0

omg thanks so much! :D

0

PLEASE accept my answer im so happy you liked it!

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