Help with team script error

Hello, I need to script the team guest as a neutral team for players by default when joining the game, what is wrong with my script? nothing happens, no output errors :frowning:

Script:

local function guestTeamJoin()
	local guestTeam = Instance.new("Team")
	guestTeam.Name = "Guest"
	guestTeam.TeamColor = BrickColor.new("Really red")
	guestTeam.AutoAssignable = true

	local guestSpawnLocation = Instance.new("SpawnLocation")
	guestSpawnLocation.BrickColor = BrickColor.new("Really red")
	guestSpawnLocation.Color = Color3.fromRGB(255, 0, 0)
	guestSpawnLocation.Neutral = true
end

game.Players.PlayerAdded:Connect(guestTeamJoin)

Is this a ServerScript or a LocalScript?

Found it. You didnt set the team’s parent to the team service.

it’s a server script in server script service:

image

and there are no teams :frowning:

Try doing what I said above. Then tell me if it works or not.

Oh :scream: how could i parent it to the the team service? :scream:

Change this line:

local guestTeam = Instance.new("Team")

To this:

local guestTeam = Instance.new("Team", game:GetService("Teams"))
1 Like

Oh I already did! now it works :smiley: thanks you a lot :smiley:

local function guestTeamJoin()
	local guestTeam = Instance.new("Team")
	guestTeam.Parent = game:GetService("Teams")
	guestTeam.Name = "Guest"
	guestTeam.TeamColor = BrickColor.new("Really red")
	guestTeam.AutoAssignable = true

	local guestSpawnLocation = Instance.new("SpawnLocation")
	guestSpawnLocation.Parent = game:GetService("Teams")
	guestSpawnLocation.BrickColor = BrickColor.new("Really red")
	guestSpawnLocation.Color = Color3.fromRGB(255, 0, 0)
	guestSpawnLocation.Neutral = true
end

No problem :slight_smile: Can you mark it as solution?

Hey, one last question… how to i set Guest Team as Neutral in the tab?
I need guest to be the neutral team and not neutral

Move the player to the team when they join. If the Neutral team is empty, It will delete itself.

1 Like

How could I do that? I’m not sure, sorry for the inconvenience :frowning:

Change your script to this:

local function guestTeamJoin(player)
	local guestTeam = Instance.new("Team")
	guestTeam.Parent = game:GetService("Teams")
	guestTeam.Name = "Guest"
	guestTeam.TeamColor = BrickColor.new("Really red")
	guestTeam.AutoAssignable = true
    player.TeamColor = BrickColor.new("Really red")

	local guestSpawnLocation = Instance.new("SpawnLocation")
	guestSpawnLocation.Parent = game:GetService("Teams")
	guestSpawnLocation.BrickColor = BrickColor.new("Really red")
	guestSpawnLocation.Color = Color3.fromRGB(255, 0, 0)
	guestSpawnLocation.Neutral = true
end

game.Players.PlayerAdded:Connect(guestTeamJoin(player))

got an error here:

image

I’m on mobile so I can’t make sure it works, sorry. Give me some moment.

Do

game.Players.PlayerAdded:Connect(guestTeamJoin)

how to i set Guest Team as Neutral in the tab?
I need guest to be the neutral team and not neutral

script:

local function guestTeamJoin(plr)
	local guestTeam = Instance.new("Team")
	guestTeam.Parent = game:GetService("Teams")
	guestTeam.Name = "Guest"
	guestTeam.TeamColor = BrickColor.new("Really red")
	guestTeam.AutoAssignable = true
	plr.TeamColor = BrickColor.new("Really red")
	

	local guestSpawnLocation = Instance.new("SpawnLocation")
	guestSpawnLocation.Parent = game:GetService("Teams")
	guestSpawnLocation.BrickColor = BrickColor.new("Really red")
	guestSpawnLocation.Color = Color3.fromRGB(255, 0, 0)
	guestSpawnLocation.Neutral = true
end

game.Players.PlayerAdded:Connect(guestTeamJoin)

Also creating a new team everytime someone joins, is that really what you want to do?

local Teams = game:GetService("Teams")
local function guestTeamJoin(player)
    if not Teams:FindFirstChild("Guest") then
	  local guestTeam = Instance.new("Team")
	  guestTeam.Parent = game:GetService("Teams")
	  guestTeam.Name = "Guest"
	  guestTeam.TeamColor = BrickColor.new("Really red")
	  guestTeam.AutoAssignable = true
      player.TeamColor = BrickColor.new("Really red")

	  local guestSpawnLocation = Instance.new("SpawnLocation")
	  guestSpawnLocation.Parent = game:GetService("Teams")
	  guestSpawnLocation.BrickColor = BrickColor.new("Really red")
	  guestSpawnLocation.Color = Color3.fromRGB(255, 0, 0)
	  guestSpawnLocation.Neutral = true
    end
end

Set guestSpawnLocation.Neutral to false

It didnt worked :frowning: