Bug - Team Changer ServerSide

game.Players.PlayerAdded:Connect(function(p)

	local function Clicked()
		if p:GetRankInGroup(9536284) >= 3 then
			p.TeamColor = BrickColor.new("Sea green")
			p:LoadCharacter()
		
		end
	end
	event.OnServerEvent:Connect(Clicked)
end)

When I click the team changer in StarterUI, everyone above that rank gets their team changed. How can I make it one person only?

Can you be more specific?
charsssssss

1 Like

When I click it, everyone in the server that is above that rank stated will get their team changed, I only want the person who clicked it to be on that team.

You should connect the function outside the PlayerAdded event. You’re connecting it everytime a new Player is added, Meaning all Players are gonna be affected no matter who fires it.

RemoteEvent.OnServerEvent:Connect(function(Player)
    -- Function runs here
end)
2 Likes

Don’t wrap that in a PlayerAdded event, instead make a function that has a player parameter (onserverevent first parameter), then check the player’s rank value

Trying this currently. Will use it

Nothing happens when I click the button.

May you please show us the code that you used on the Server-side? I tested it and it worked perfectly for me.

1 Like

local folder = game:GetService("ReplicatedStorage").TeamChangeEvents
local event = folder.CA
local sofcom = folder.CANSOFCOM
local cfmp = folder.CFMP
local civ = folder.CIV
local core = folder.CORE
local hq = folder.HQ
local cadtc = folder.CFDTC



	

	event.OnServerEvent:Connect(function(p)

	
	local function Clicked()
		
		if p:GetRankInGroup(9536284) >= 3 then
			
			p.TeamColor = BrickColor.new("Sea green")
			
			p:LoadCharacter()
			
			event.OnServerEvent:Connect(Clicked) 
			

			
		
	end

	end

end)```

Connect OnServerEvent with the Clicked function, not a anonymous function

1 Like
		Clicked.OnServerEvent:Connect()

Not like that, put the function in the parentheses

1 Like

Declare the Clicked function, And then Connect it. Do not connect the Event inside the Clicked function.

-- Declare the function
-- DO NOT CONNECT IT TWICE!
event.OnServerEvent:Connect(Clicked)
2 Likes

Should it be something like this?

local p = game.Players.LocalPlayer		

		
			

				local function Clicked()
if p:GetRankInGroup(9536284) >= 3 then
			
			
			p.TeamColor = BrickColor.new("Sea green")
			
			p:LoadCharacter()
			
			event.OnServerEvent:Connect(Clicked)


			
		
	end

	end

Put the event in the global scope, not in the function

Sorry for late response.

1 Like

What does that mean? I don’t understand

local p = game.Players.LocalPlayer

local function Clicked()
    if p:GetRankInGroup(9536284) >= 3 then
	   p.TeamColor = BrickColor.new("Sea green")
	   p:LoadCharacter()
   end
end

event.OnServerEvent:Connect(Clicked)
1 Like

Ok, I will use this. But what if I have multiple teams? I copy and paste?

local function Clicked(player, teamColor)
    if p:GetRankInGroup(9536284) >= 3 then
	   p.TeamColor = teamColor
	   p:LoadCharacter()
   end
end

event.OnServerEvent:Connect(Clicked)

Duplicate function called on line 7