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.
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
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
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"
},
}
}