Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do I switch player's teams based on their game?

so, i am trying to make a meeting/exams/class place, and i want to be able to assign people with their name. I have already tried this technique:

function setTeam(player, teamName) newPlayer.TeamColor = game.Teams[teamName].TeamColor if newPlayer.Character then

   end

end

setTeam(game.Players.epicly2000, "?Academy?") setTeam(game.Players.proimaaz153, "?Academy?")

if someone could help me with this problem, it'd be greatly appreciated. Thank you!

2 comments

0

sorry, this was the code:

0

function setTeam(player, teamName) newPlayer.TeamColor = game.Teams[teamName].TeamColor if newPlayer.Character then end end

1 answer

--// Set up Variables
local academy = game:GetService("Teams").Academy

--// When player joins
game.Players.PlayerAdded:connect(function(player) -- when the player spawns
	player.CharacterAdded:connect(function(character)
		if player.Name == "epicly2000" then -- if their username is epicly2000
		player.Team = academy -- their team is set to academy
		end
	end)
end)

It seems the system you're attempting to use is overly complex, however I can't ensure the above will work as I haven't been able to test it.

4 comments

0

Hmm @BouncingBrenda that code doesn't seem to work. I'll send it to you in the form I put it in:

0

local academy = game:GetService("Teams").Academy game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if player.Name == "epicly2000" then player.Team = ?Academy? end end) end)

0

I put it in basically the exactly same way you did, yet it did not come out correctly. I'll keep researching for solutions. Thanks for your help!

0

Is the team in the teams section named "Academy" and exactly that?

This discussion is preserved as it was. New answers, comments, and votes are closed.