This team changer is not working

Hello, I’m doing a main menu with a team changer.
I added all the teams into separated frames, as you can see at this photo image

That local script controls everything at the main menu (blur background, camera position, GUI tweening…) and everything is working fine. Everything works except the team changer

--// Team Changer \\--

script.Parent.CO.Join.MouseButton1Click:Connect(function()
	local Response = game.ReplicatedStorage.MainMenu.ChangeTeam:InvokeServer(game.Teams["Correctional Staff"])
	wait(0.1)
	if Response == "Success" then
		repeat wait()
			game.Workspace.Camera.CameraType = Enum.CameraType.Custom
		until game.Workspace.Camera.CameraType == Enum.CameraType.Custom
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
		Blur.Enabled = false
		wait(0.2)
		game.ReplicatedStorage.Respawn:FireServer()
	end
end)

We can find this script at the local script of the main menu.

The team change is controlled by this script, located at ServerScriptService

game.ReplicatedStorage.MainMenu.ChangeTeam.OnServerInvoke = function(plr, code, team)
	if team == game.Teams.Inmate then
		plr.Team = game.Teams.Inmate
		return "Success"
	elseif team == game.Teams["Correctional Staff"] then
		if plr:GetRankInGroup(6291775) >= 4 then
			plr.Team = team
			return "Success"
		end
	elseif team == game.Teams["Emergency Response Team"] then
		if plr:GetRankInGroup(6291775) >= 6 then
			plr.Team = team
			return "Success"
		end
	elseif team == game.Teams["High Command"] then
		if plr:GetRankInGroup(6291775) >= 12 then
			plr.Team = team
			return "Success"
		end
	elseif team == game.Teams["Redacted"] then
		if plr:GetRankInGroup(4965929) >= 2 then
			plr.Team = team
			return "Success"
		end
	end
	
end

game.ReplicatedStorage.Respawn.OnServerEvent:Connect(function(plr)
	plr:LoadCharacter()
end)

(And i’m using a remote function, located at ReplicatedStorage)

I already changed some parts of the script a lot of times, but I can’t make it work.

1 Like

please show errors

30 characters

There’s no output errors, and also there’s no errors at the script analysis tool :confused:

can you place a print statement in the server script to check if it is even firing?

I placed it, it is not firing :confused:

now place a print statement after the button click to see if the button is evne being clicked

Ok, i placed it and is not being clicked :confused:

weird... everything should work...
script.Parent.CO.Join.MouseButton1Click:Connect(function()

image

In the LocalScript you are invoking function with a team object.

local Response = game.ReplicatedStorage.MainMenu.ChangeTeam:InvokeServer(game.Teams["Correctional Staff"])

But on the server side you defined 3 variables

game.ReplicatedStorage.MainMenu.ChangeTeam.OnServerInvoke = function(plr, code, team)
--plr is a player, code is a team object and team is nil when is invoked from this local script
end

If after changing it still doesn’t work, send to server only Name of team instead of a team object and do checks to that argument. Also to prevent infinite yield you need to return something if server doesn’t change player’s team (if they don’t meet the requirements for example)

1 Like