Team changer GUI not teaming the players

Okay, so recently I have been trying to make an advanced team gui that you could easily configure in a module script. The strange thing is it does everything perfectly it just doesn’t actually team the player. I tried debugging it with print but I didn’t get any errors/nil values, nor did I get any errors in general in the output. There are 3 different scripts connected, one being the Local Script, Server Script and Module Script. I will list all of them down below. Any and all help is appreciated so thank you in advance! :smile:

Local Script:

local player = game:GetService("Players").LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
local teammodule = require(replicatedstorage:WaitForChild("ModuleScript"))
local switchteam = replicatedstorage:WaitForChild("SwitchTeam")

local teamlist = script.Parent:WaitForChild("TeamList")

local avaliableteams = teamlist:GetChildren()

for a = 1,#avaliableteams do
	if avaliableteams[a].ClassName == "TextButton" then
		if player:IsInGroup(avaliableteams[a].Name) then
			
		else
			avaliableteams[a]:Destroy()
		end
		
		avaliableteams[a].MouseButton1Down:Connect(function(changeteam)
			print("Working")
			for i,v in pairs(teammodule) do
				print(v)
				if avaliableteams[a].Name == i then
					print("Avaliable Team")
					switchteam:FireServer(v[2],v[1])
					print("Fired")
				end
			end
		end)
	end
end

Server Script:

local plr = game:GetService("Players").LocalPlayer
local teams = game:GetService("Teams")
local replicatedstorage = game:GetService("ReplicatedStorage")
local switchteam = replicatedstorage:WaitForChild("SwitchTeam")

function changeteam(player,teamcolor,groupid)
	if player:IsInGroup(groupid) then
		if player.TeamColor ~= teamcolor then
		print("Event fired")
		player.TeamColor = BrickColor.new(teamcolor)
		print(teamcolor)
		player:LoadCharacter()
		end	
	end
end

switchteam.OnServerEvent:Connect(changeteam)

Module Script:

local module = {
	["5131370"] = {5131370,"Deep orange"},
	["262619"] = {262619,"Really black"},
	["5996731"] = {5996731,"Dark stone grey"}
}

return module
2 Likes

This system can be easily exploited. The client can send over any group ID and any Team Color. You should handle this entirely on the Server instead of using a RemoteEvent.

2 Likes

By this would you mean, transfer this all over to a ServerScript?

3 Likes

Yes, you would have to transfer this over all to a ServerScript.

2 Likes

It’s a GUI, those can’t be handled on the server.

2 Likes

GUI’s are not usually handled on the Server however in this case it is preferred. It is possible to handle GUI on the Server but It is not recommended. (depends on use case).

2 Likes

You could make this use a RemoteEvent instead of just ServerScript.
Heres a quick example of how this would work without having it being exploitable.

--LocalScript
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent:FireServer("Dark stone grey") --Fire the Team Color as the argument 

--ServerScript
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local TeamsTable = {Team1 = {Color = "Dark stone grey", ID = 12345}}

RemoteEvent.OnServerEvent:Connect(function(Player, TeamColor)
	if TeamColor then
		for _,v in pairs(TeamsTable) do
			if TeamColor == v.Color then
				if Player:IsInGroup(v.ID) then
					Player.TeamColor = BrickColor.new(v.Color)
					Player:LoadCharacter()
				end
			end
		end
	end
end)
1 Like