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:
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
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
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:
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