I’ve made a team change command with Cmdr. I need help on the Server side of the command.
Here is what I have so far:
-- teamchangeServer
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
return function(player, team)
local team = team.Name
if team then
player.Team = team
end
return("Changed Team.")
end
And here is the other script
return {
Name = "changeteam",
Aliases = {"teamchange", "ct", "tc"},
Description = "Changes the person who is using the command's team.",
Group = "Developer",
Args = {
{
Type = "team",
Name = "Team",
Description = "The team you want to switch to"
},
}
}
I am just confused on how I would make the server script because it is not actually changing the team but the console is saying that team was changed. Any help would be much appreciated.
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local plr = Players.LocalPlayer
return function(player, team)
local team = team.Name
plr.Team = team
return("Changed to team "..team..".")
end
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
return function(player, team)
local actualTeam = Teams[team]
if actualTeam then
player.Team = actualTeam
return("Changed Team.")
end
return("No team with name "..team)
end
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
return function(player, team)
local actualTeam = Teams[tostring(team.Name)]
if actualTeam then
player.Team = actualTeam
return("Changed Team.")
end
return("No team with name "..team)
end
Now it’s just saying, “Changed Team.” Though, I don’t understand because It’s not a string that I’m typing in. I’m selecting it from Cmdr’s types called Team.
The player variable in there is the context so what I would try to do is probably player.Executor.Team and then try setting the team to whatever team the team variable returned.
I think you’re getting an error because the plrteam variable is the name of the team argument. I would probably just remove the team.Name and see if it works.
Okay, I think this is the solution you’ve been looking for.
Now, if we look at this line:
return function(player, team)
local team = team.Name
if team then
player.Team = team --you're trying to set an object to a string
end
return("Changed Team.")
end
It looks like you’re setting an object, our team, to a string value. This is not what you want.
Instead, you should do this:
return function(player, team)
local team = Teams:FindFirstChild(team.Name)
if team then
player.Team = team
end
return("Changed Team.")
end
This edited bit up here, instead, goes into the Teams instance and looks for the team that you want.