Team changer gui not working correctly

I tried to make a game that has bunch of teams. When people joined, there will be a gui like this and player can choose which team they want to be in to.

It actually works perfectly, the script, localscript, and remote event changes the player’s TeamColor but somehow the player was not in the team. (Ex: I choose compass point team with crimson teamcolor on it. It does changes my teamcolor to crimson, but not my team)
image
image
^^^ this is the teamcolor inside my player model
image

there’s no errors. Any idea on how to fix this? also I’m using some help from this post so I’m not sure if there’s a problem with my script or something else

things included in this topic:

Remote Events

image

Local script (inside the team select gui)

image

local revent       = game.ReplicatedStorage.ChangeTeam
local menubutton
local background   = script.Parent:WaitForChild("Background")

--frames
local selectframe  = background.SelectTeamHandler.TeamSelect
local ctgr_civilian= selectframe["Category:Civilians"]
local ctgr_combat  = selectframe["Category:Combatant"]
local ctgr_departm = selectframe["Category:Department"]
local ctrg_medic   = selectframe["Category:Medic"]


-- team buttons
-- category: civ
local btn_civilians= ctgr_civilian.Teams.Civilians

-- category: combatant
local btn_comppoint= ctgr_combat.Teams["Compass Point"]
local btn_lockbreak= ctgr_combat.Teams["Lock Breakers"]
local btn_qckmatch = ctgr_combat.Teams["Quick Match"]
local btn_trackmap = ctgr_combat.Teams["Track Mappers"]
local btn_wldwarrs = ctgr_combat.Teams["Wild Warriors"]

-- category: department
local btn_researchr= ctgr_departm.Teams.Researcher

-- category: medic
local btn_lifeline = ctrg_medic.Teams["Life Line"]




--Teams
local civilians    = "Bright green"
local compasspoint = "Crimson"
local lifeline     = "Lime green"
local lockbreakers = "Cyan"
local quickmatch   = "Deep orange"
local researcher   = "Pastel Blue"
local trackmappers = "Magenta"
local wildwarriors = "Lapis"



--button functions


-- civilians
btn_civilians.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(civilians))
end)

-- compass point
btn_comppoint.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(compasspoint))
end)

-- lock breakers
btn_lockbreak.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(lockbreakers))
end)

-- Quick Match
btn_qckmatch.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(quickmatch))
end)

-- Track Mappers
btn_trackmap.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(trackmappers))
end)

-- Wild Warriors
btn_wldwarrs.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(wildwarriors))
end)

-- Researcher
btn_researchr.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(researcher))
end)

-- Life Line
btn_lifeline.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(lifeline))
end)

game:GetService("ReplicatedStorage").PlayerEnter.OnClientEvent:Connect(function(player)
end)
Server Script
game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, teamColor)
	player.TeamColor = teamColor
	player:LoadCharacter()
	player.PlayerGui.SelectTeam.Enabled = false
	player.PlayerGui.Loading:Destroy()
end)
local player = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(players)
	game.ReplicatedStorage.PlayerEnter:FireClient(players)
end)

Try disabling player.Neutral and using player.Team

You are changing the team color and not the team itself.

using player.TeamColor changes player team too(I think so because im using it to change teams)

1 Like

isn’t it will change the player’s team automatically too. Imma try rewrite the script

@kozak456pl said it does, I’m not sure, it’s better to try tho.

1 Like

Hi!

Instead of firing the TeamColor, you can just send the name of the team.

Also, as @DoctorFartPhD said, change the Player’s Team property and not the TeamColor property. make sure that the team exists, or else it will error.

Here is the rewritten Server Script:

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, team: string)
	if game:GetService("Teams"):FindFirstChild(team) then
        player.Team = team
	    player:LoadCharacter()
	    player.PlayerGui.SelectTeam.Enabled = false
	    player.PlayerGui.Loading:Destroy()
    else
        warn("@"..player.Name.." asked to change to a team that doesn't exist!") --Just in case
    end
end)
game:GetService("Players").PlayerAdded:Connect(function(plr)
	game.ReplicatedStorage.PlayerEnter:FireClient(plr)
end)

and the rewritten Local Script:

--Change the brickcolor of the team to the actual team name and not the teamcolor
local revent       = game.ReplicatedStorage.ChangeTeam
local menubutton
local background   = script.Parent:WaitForChild("Background")

--frames
local selectframe  = background.SelectTeamHandler.TeamSelect
local ctgr_civilian= selectframe["Category:Civilians"]
local ctgr_combat  = selectframe["Category:Combatant"]
local ctgr_departm = selectframe["Category:Department"]
local ctrg_medic   = selectframe["Category:Medic"]


-- team buttons
-- category: civ
local btn_civilians= ctgr_civilian.Teams.Civilians

-- category: combatant
local btn_comppoint= ctgr_combat.Teams["Compass Point"]
local btn_lockbreak= ctgr_combat.Teams["Lock Breakers"]
local btn_qckmatch = ctgr_combat.Teams["Quick Match"]
local btn_trackmap = ctgr_combat.Teams["Track Mappers"]
local btn_wldwarrs = ctgr_combat.Teams["Wild Warriors"]

-- category: department
local btn_researchr= ctgr_departm.Teams.Researcher

-- category: medic
local btn_lifeline = ctrg_medic.Teams["Life Line"]



-- Button functions
-- Civilians
btn_civilians.MouseButton1Click:Connect(function()
    revent:FireServer("Civilians")
end)

-- Compass Point
btn_comppoint.MouseButton1Click:Connect(function()
    revent:FireServer("Compass Point")
end)

-- Lock Breakers
btn_lockbreak.MouseButton1Click:Connect(function()
    revent:FireServer("Lock Breakers")
end)

-- Quick Match
btn_qckmatch.MouseButton1Click:Connect(function()
    revent:FireServer("Quick Match")
end)

-- Track Mappers
btn_trackmap.MouseButton1Click:Connect(function()
    revent:FireServer("Track Mappers")
end)

-- Wild Warriors
btn_wldwarrs.MouseButton1Click:Connect(function()
    revent:FireServer("Wild Warriors")
end)

-- Researcher
btn_researchr.MouseButton1Click:Connect(function()
    revent:FireServer("Researcher")
end)

-- Life Line
btn_lifeline.MouseButton1Click:Connect(function()
    revent:FireServer("Life Line")
end)

menubutton = player.PlayerGui.Menu.TeamSelect.MenuButton

menubutton.MouseButton1Click:Connect(function() --No remote function is needed, as this can be handled by the client (and is the most efficient way to do it)
    selectframe.Visible = not selectframe.Visible
end)

Hope this helps!

1 Like

should I add like

local player = game.Players.LocalPlayer

because it doesn’t seem you wrote it at the local script

Which script? And why would you add it if you don’t need it?

image

My bad. Replace it with game:GetService("Players").LocalPlayer since creating a variable for it is useless, unless you are only using it multiple time

that’s ok, anyways can I know where does “menubutton” leads to? it looks like it is a button. Is it like a button to make the selectframe’s visible to false? I will try to find or make a new gui if yes

Hello, so I tried doing how your team changing system works and noticed there is a problem with doing it by changing the player’s team color. The server doesn’t change the player’s team by changing it’s TeamColor value.

Check the photo below:

Image

It reloads my avatar but doesn’t change my team.

I see there has been solutions posted in this thread, but if you want to stick with doing it by BrickColor for some purposes. Here’s something you might want to try:

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, teamColor)
	local requestValid = false
	for _, team in pairs(game:GetService("Teams"):GetTeams()) do
		if team.TeamColor == teamColor then
			player.Team = team
			requestValid = true
		end
	end
	if not requestValid then return end
	
	player:LoadCharacter()
	player.PlayerGui.SelectTeam.Enabled = false
	player.PlayerGui.Loading:Destroy()
end)

game.Players.PlayerAdded:Connect(function(player)
	game.ReplicatedStorage.PlayerEnter:FireClient(player)
end)
2 Likes

I think he used BrickColor because Spawnpoints uses TeamColor. The TeamColor for checkpoints is to make them for certain teams only (That have the color as the team).

The efficient way is to set the Team Property instead of the TeamColor property.

after hours of struggling about this. I finally fixed it! thank you to everyone who replied and helped me here especially @TheLikerYT and @LuaPyX! and here’s the final scripts for anyone in the future.

Teams

You can add as many teams as you want

Remote Events

image

Server Script (placed at serverscriptservice)
game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, teamColor)
	local requestValid = false
	for _, team in pairs(game:GetService("Teams"):GetTeams()) do
		if team.TeamColor == teamColor then
			player.Team = team
			requestValid = true
		end
	end
	if not requestValid then return end

	player:LoadCharacter()
	player.PlayerGui.SelectTeam.Enabled = false
	player.PlayerGui.Loading:Destroy()
end)

game.Players.PlayerAdded:Connect(function(player)
	game.ReplicatedStorage.PlayerEnter:FireClient(player)
end)
LocalScript (placed underneath your gui, example:

image

wait(1)
local revent       = game.ReplicatedStorage.ChangeTeam -- this leads to ChangeTeam remote event
local background   = script.Parent:WaitForChild("Background") -- this is actually optional and you can skip this line, but for easier scripting, I always use this.

--frames
local selectframe  = background.SelectTeamHandler.TeamSelect -- This is the main gui (parent for all of the buttons) again I wrote this for easier scripting so this is optional too.
local ctgr_civilian= selectframe["Category:Civilians"] -- this leads to the button's category which is a frame, this is optional too.  And if you dont use category like this, you can skip this part (What I meant by category is like the picture I'm replying too.)


-- team buttons
-- category: civ
local btn_civilians= ctgr_civilian.Teams.Civilians -- this leads to the button. (You can change its name as you like)

--Teams
local civilians    = "Bright green" -- This is for the team's teamcolor



--button functions

-- civilians
btn_civilians.MouseButton1Click:Connect(function()
	revent:FireServer(BrickColor.new(civilians)) -- This will make the system tells remote event to change your team.
end)


game:GetService("ReplicatedStorage").PlayerEnter.OnClientEvent:Connect(function(player) -- this line is for connecting the local script to the server.
	player.PlayerGui.SelectTeam.Enabled = false
	player.PlayerGui.Loading:Destroy()
end)

That’s all, thank you for reading and helping! if you have some questions about this, feel free contact me or reply (I forgot can you reply after this or not).

1 Like