How would I fetch/obtain a player's team via workspace/local player?

I’m trying to fetch a player’s team for a portable radio tool to show their team, however, I cannot obtain their team from the workspace.Player (local player)–perhaps there’s another way?

I looked for some help here and the only possible way I could think of is somehow obtaining the player’s name color and see if it matches an associated team but I don’t know where to find (I also tried to use player.name.color==team1.teamcolor just to try something)

Sample Code:
(I already know how to fetch teams from team service, thats what variables Team1&2 are)

local ROLE=""
local Players = game:GetService("Players")

local player = Players.LocalPlayer

if player.Name.Color==Team1.TeamColor then
	ROLE=" [Team1]"
end

if player.Name.Color==Team2.TeamColor then
	ROLE=" [Team2]"
end

I’ve also tried:

	local localplayerteam = game.Players.LocalPlayer.Team

if localplayerteam==Team1 then
	ROLE=" [Team1 ]"
end

if localplayerteam==Team2 then
	ROLE=" [Team2 ]"
end

error for both: Team is not a valid member of Model “Workspace.Juicy_Fruit”

Any ideas?

I’m surprised you’re getting an error like that since I see no mention of the Character property, maybe try this?

local ROLE = ""
local Players = game:GetService("Players")
local player = Players.LocalPlayer

if player.Team == Team1 then
	ROLE = " [Team1]"
end

if player.Team == Team2 then
	ROLE = " [Team2]"
end

Make sure you’re using this on a localscript

Team is not replicated. You will need to find the team on the server then you can return it to the client via a RemoteFunction.

I did a big oopsie on my part and was editing the wrong one–but you led me to figuring this out and I used your code so Ill give solution (I had an old copy of the script in use which used the character model which was why I was getting the error)

It works now though, maybe my code would of worked as well but I’m content with this.

1 Like

Anytime! if you have anymore issues don’t be afraid to make another post!