Script is printing wrong team

Hola! I’ve done a quick and simple script which is making a list where all the teams are in. In these teams tables im also adding the people which are in which team are. So like, when I join and I’m in Team2, it should add me into the list under the table Team2. The problem is now. I join with Team2 but it’s saying no. DivScripts is in Team1. I mean this:


I have also even waited 10 seconds and it’s still wrong. Anyone knows how I would fix it?

CODE:

local teamConfiguration = {
	["Team1"] = {
		"Team1",
		"Team2",
	};
	["Team2"] = {
		"Team2",
		"Team1",
	};
}

local teamAllowness = {
	
}

for i,v in pairs(game.Teams:GetChildren()) do
	teamAllowness[v.Name] =  {}
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		wait(10)
		print(player.Team)
		teamAllowness[player.Team.Name][player.Name] = player.UserId
		print(teamAllowness,teamAllowness[player.Team.Name])
	end)
end)


Best regards,
Div!

1 Like

Can you please send your script (in text) so we can understand what the problem really is? We wouldn’t be able to help without having the script.

pov: no script provided

2 Likes

Apologies! I have just forgot to put it in. xD. It’s now in!

1 Like

Where are you adding the player to the table teamAllowness? I see that you are updating it when the player respawns, but where are they being added?

1 Like

Oh. My fault with that.I will edit it so it happens only when a player joins. I am adding the player to the table TeamAllowness → Team of the Player. This can be found in the line 23. But like the main question is. Why is it printing Team1 when I am in Team2???

On line 23 you are editing the table, where are you adding the player to the table?

If I knew where the player is being added to the table, I could help you with this.

Oh. It’s a method to assing things to tables too. You can say for example. Table[“Hi”] = nil. It would be then: Table = {[“Hi”] = nil}. :slight_smile:

Solution: Just use BrickColor. Roblox seems a bit buggy at this point.

This code is fairly obselete considering you can query a team’s players via the ‘GetPlayers()’ method.

https://developer.roblox.com/en-us/api-reference/function/Team/GetPlayers

You also have the ‘PlayerAdded’/‘PlayerRemoving’ signals for when a player joins/leaves a team respectively.