Team Change Command w/ Cmdr

The last thing I can think of is to replace FindFirstChild with a WaitForChild. This is very much NOT the best solution, and is generally not right for this situation, given the fact that it can cause an infinite yield.

I will try and devise a solution in the meantime.

After looking at the script, I found a crucial issue, assuming that player is a string:

You’re trying to set a string value’s property to an object. This is not what you want.
And an issue on my end, I accidentally forgot to change team.Name to team, assuming this also, is a string.

With all said, here is your solution:

-- teamchangeServer

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

return function(player, team)
	local gotteam = Teams:FindFirstChild(team)
	local gotplayer = Players:FindFirstChild(player)
	if gotteam and gotplayer then
		gotplayer.Team = gotteam
		return("Changed Team.")
	else
		return("Cannot change team; team is nil.")
	end
end

I got this error:
tables cannot be cyclic

Are both parameters player and team strings? If not, you might want to do this instead:

-- teamchangeServer

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

return function(player, team)
	if team and player then
		player.Team = team
		return("Changed Team.")
	else
		return("Cannot change team; team is nil.")
	end
end

team is a type that gives you all the teams in the game Types | Cmdr

This time I got no error but it didn’t change teams

Ah. Sorry, I am not very familiar with Cmdr.

The output that the function returns should determine the issue to some extent.

Does it return “Changed Team” or “Cannot change team?”

It returned Changed Team
image

Try using these args:

return {
	Name = "changeteam",
	Aliases = {"teamchange", "ct", "tc"},
	Description = "Changes a player's team to the specified team.",
	Group = "Developer",
	Args = {
		{
			Type = "player",
			Name = "Player",
			Description = "The player to set the team of."
		},
		{
			Type = "team",
			Name = "Team",
			Description = "The team you want to switch to."
		},
		
	}
}

I’ve used those args already. Sorry, I didn’t update it in the original.

return {
	Name = "changeteam",
	Aliases = {"teamchange", "ct", "tc", "team"},
	Description = "Changes the person who is using the command's team.",
	Group = "Developer",
	Args = {
		
		{
			Type = "player",
			Name = "Target",
			Description = "The person who's team you're switching"
		},
		
		{
			Type = "team",
			Name = "Team",
			Description = "The team you want to switch to"
		},
		
	}
}

Try doing player.Team = game.Teams[team]

1 Like