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)
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.