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

How to I access the Player's Team?

Asked by 3 years ago

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) 
0
I'm going to look into this :) Clorize 31 — 3y
0
thanks :)) youngsavagehard 20 — 3y

1 answer

Log in to vote
0
Answered by
Clorize 31
3 years ago
Edited 3 years ago

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.

0
omg thanks so much! :D youngsavagehard 20 — 3y
0
PLEASE accept my answer im so happy you liked it! Clorize 31 — 3y
Ad

Answer this question