Team Changer Malfunction

I’m making a Royal Air Force base and am struggling to get my TeamChanger to change the team. I’ve read up and down the Output tab three times and couldn’t resolve the problem. Here are some screenshots of the relevant scripts:

This is the script that is meant to change the player’s team, if they are in the group:


This is the script that is inside the “Royal Air Force” button:
image

I went over the TeamColor of the teams and can’t resolve it.
Please help,
Thanks.

It is because you’re trying to change the player’s TeamColor, you should be trying to change their actual Team. You can do this by indexing the property Team on a player object and setting it to a team object, such as game.Players.CleverSource.Team = game.Teams.TeamName. This method will require that the team does exist, you might want to add some “sanity checks” to ensure the team that you’re assigning does exist.

A possible solution would be changing your ChangeTeam function to do this:

function ChangeTeam(p, v)
  p.Team = game.Teams[v]
  local char = p.Character
  local h = char.Humanoid
  h.Health = 0
end
5 Likes

Can you elaborate in which script to put this in?

1 Like

It would be the one that you use for team changing, you already have this function, I’ve edited it to achieve the result which you wish to have.

1 Like

I’d just like to point out that your table only has 5 elements, and you try indexing 6 and 7. I feel like you’re indexing might be the issue here. Same thing goes for your group table, you index 5 when it only has 2 elements

1 Like

You commented the indexes to the right of the table, so where did your “RAF” team become 2 instead of 1 like the comment states?

I was trying to find minor bugs so will get to that asap

Could I make one more suggestion?

Instead of making a table of Team colors, you are allowed to change the “Team” property of the player. So why not just do that?

1 Like

Can you elaborate for me please?

Is this correct now? I changed the indexes and edited the function that @CleverSource suggested:

1 Like

Using his method you’d just want to send the team name itself to the function.

And what could I do to improve the method?

Instead of sending ‘colours’ BrickColor.new("ElectricBlue")
You should probably send the ‘team name’ as shown in game.Teams in the explorer.
because the way you have setup the ChangeTeam function is you are finding a team

So something like this for the table:

local TeamNames = {"Team1", "Team2", "Team3"} 

EDIT:

I see you’re getting a red line because you forgot an end here:

Hi,
Can you explain how this would change?
PS I won’t reply after this as I’m busy.

Instead of using that function (changeTeam) do this

if team == "Civilians" then 
player.TeamColor = TeamColors[7]
player:LoadCharacter()

Sorry for the late response.

here is how the code would look

local GroupIds = {1, 2, 3}
local TeamNames = {"Name1", "Name2", "Name3"}

function ChangeTeam(p, v)
     p.Team = game.Teams[v]
     p:LoadCharacter()
end

game.ReplicatedStorage.ChangeTeams.OnServerEvent:Connect(function(player, team)
      if team == "Name1" and player:IsInGroup(GroupIds[1]) then
            ChangeTeam(player, TeamNames[1]
      end
end

Since you’re already passing along a string containing the name of the team, you can get rid of the teamcolors table by simple doing

player.Team = game.Teams[team]

It looks like you use comic sans. Changing your editor font should fix the problem. /s

1 Like

I’m not sure the font is the issue.
The font is an external add-on, so it has no side effect apart from it is a wee bit more difficult to read.