Checking the players team

I have three teams, green blue and lobby.

When the teams are randomized I get put on the green or blue team.
After that it prints my team e.g

print(player.Team.Name)

for some reason it always prints ‘Lobby’, is there any explanation / fix to this?
p.s when I do the same in the command bar it works just fine.

6 Likes

I’d bet that the print(player.Team.Name) code run just slightly earlier than the team change. Show us the code around it that triggers that line.

1 Like

The team change is during the intermission, which then waits 30 seconds and the print script runs.
Very confusing as to why it doesn’t work. Before the print script runs, it is also clear my team is listed as ‘Green’ or ‘Blue’

image

1 Like

Could you possibly provide more code so it would be easier to understand?

1 Like
--I simplified it to just one team to see the result.
while true do
wait(10)
game.Players.Fruxan.Team = game:GetService('Teams').Green
wait(30)
print(game.Players.Fruxan.Team.Name)
end
--No different results.
1 Like

That script doesn’t randomize whether you will be placed on Green or Blue team, for sure. It should always print Green because you set yourself to have Green team.

Are you sure that the script printed Lobby, and not other scripts?

1 Like

I had simplified it to just changing the team to Green instead of randomizing, just to test. Also yes, as those are the only scripts I used in my ‘Test’ place.

1 Like

The script you have shared works fine for me. Please share the original script and we can help you debug this matter further.

1 Like

Unfortunately and strangely enough, it doesn’t work for me.

I tested this script, and when I changed my team, it still prints my old team. Here’s the script that I used:

function checkTeam()
	local team = game.Players.slothfulGuy.Team.Name
	print(team)
end

while true do
	wait(2)
	checkTeam()
end
1 Like

That’s basically what I want to do. I want to make an if statement, if the players team is green then respawn the player etc. Problem is, it keeps saying it’s not on green team, and its still in the lobby team.

1 Like

I wrote a slightly more complex version of your script to verify the issue. This is running in a Script parented to ServerScriptService

local playerService = game:GetService("Players")
local teamService = game:GetService("Teams")

playerService.PlayerAdded:Connect(function (player)
	local teams = teamService:GetChildren()
	local i = 0
	while wait(1) do
		i = (i + 1) % #teams
		local oldTeam, newTeam = player.Team, teams[i + 1]
		player.Team = newTeam
		print(oldTeam, newTeam, player.Team)
	end
end)

I am not observing the issue you are referring to.

Perhaps you’re setting the team from the client when you should be setting it from the server?

5 Likes

Wow I completely forgot, It was a localscript. This whole time, and it was such a simple fix. Thank you.

6 Likes

Thank you from guy in the future

2 Likes