Where is the players team stored inside the object?

I feel like an idiot asking this, but I can’t figure out how to get the player object without parameters in a function. I have code that isn’t running inside a function, so I can’t pass paramters into it. How do I get the players team? With parameters you just do player.Team=game.Teams.TeamName

you have it completely correct. To check which team it is you quite literally pass that exact code into an if statement with an extra equals sign.

if player.Team == game.Teams.TeamName then

you cant access a certain player’s team without a parameter of the player unless you know their name to get the player object with :findfirstchild(). you could loop through all the players though with a getchildren() pairs loop (for i, player in pairs(game.Players:GetChildren()) do) and get their team from there. otherwise there is no way to get a player’s team without the player object

This isn’t in a function so how do I get the player.Team?

Like so?

for i, player in pairs(game.Players:GetChildren()) do
		player.Team = game.Teams.Spectators
	end

yes, that should work, although I recommend using :GetPlayers() to get all of the players and not everything parented to Players.

yep just like that, it will loop through all players (this excludes if a new player joins after it ran or during its running) and will change their team

players objects can only be parented to players

No, anything can be parented to players, that’s why they went through the trouble of making a whole separate functions just to get the players.
image

you could just add a one line check to make sure its a player object but ok

There’s no point in using an extra one-line check when you don’t need the extra line.

Also can I load the Character from the player object using :LoadCharacter()? When I tried i got an error that said this:

if your script is running before the character first loads then you need to add delay otherwise it cant find the character description

so do I add a task.wait(), how do I do that?

or do I somehow wait for the child, I’m so confused

use something like

for i,player in pairs(game:GetService("Players"):GetPlayers()) do
	if not player.Character then
		player.CharacterAdded:Wait()
	end
	player:LoadCharacter()
end
1 Like

you could use task.wait(1) at the very top or just wait for the character to be added, either way works (for characteradded do what the guy above me did) note: using task.wait(1) is temporary, you shouldnt really use it in this way but for testing its fine

I should’ve stated this earlier but this is for a game with a round system. I’m having a lot of trouble making a place for the player to go when they aren’t in the actual game, such as if they join to late or have died.

Does anyone know how this works? I have two teams, a Players team and a Spectator team along with two spawnpoints (1 for each team). The if loop right now is at the end, and goes when the game ends, it finds the players team and sets it to spectator.

ohhh, so for if they joined late you could have a playeradded function and check if the round is already running if so then either team them to spectators or if spectators is the only team with auto assign on then just dont do anything

for if they died you could inside a playeradded function within a characteradded function connect another function that calls when the humanoid dies then team them to spectators

code example:

game.Players.PlayerAdded:Connect(function(player)
	if game.ServerStorage.IsRoundRunning.Value == true then -- you can change where this is
		player.Team = game.Teams.Spectators
	end
	
	player.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
			player.Team = game.Teams.Spectators
		end)
	end)
    -- player.CharacterRemoving also works (without the died function inside it)
end)
1 Like

For the second bit of your code I already have something similiar

player.Character:BreakJoints()
savedPlayerPositions[player] = nil -- Ignore this, it is just for my game, not actually needed 
player.Team=game.Teams.Spectators

Instead of detecting if the player is dead it just breaks the joints (which kills) and then changes teams

the player.Character.Humanoid.Died function still calls whenever you break their joints so changing their team in there is better than changing it when you kill them