I wanted to make a script which creates a new team whenever a player joins the game and sets the name of the team to the player’s display name.
I wrote this code but I couldn’t figure out how to get a player’s display name and make it the name of the team and also put the player in the team.
game.Players.PlayerAdded:Connect(function()
local teams = game:GetService("Teams")
local player = game:GetService("Players")
local newTeam = Instance.new("Team", teams)
newTeam.Name = "Team"
newTeam.AutoAssignable = false
end)
You can request the players name through the PlayerAdded function and use it like so.
game.Players.PlayerAdded:Connect(function(Player) -- We request the player's name
local teams = game:GetService("Teams")
local player = game:GetService("Players")
local newTeam = Instance.new("Team", teams)
newTeam.Name = Player.DisplayName -- And we get their display name and assign it to the team's name
newTeam.AutoAssignable = false
end)