Team indicator issues, team change is executed on client but not in-server

Trying to make a team overhead gui with flag indicators (for now I’m using a textlabel as an easier cover-up)

Issue is that even though the team change to either ‘PAVN’ or ‘ARVN’ is executed within the client, but server still sees the player as part of ‘SPECTATOR’ so the label on the overhead BillboardGui remains unchanged - only when I switch to Server view and manually put myself into one of the teams does the label change.


visualized issue


client view, registers


server view, doesn’t register


after manual server adjustment

Basically speaking, I want to make sure that the label also changes to the corresponding team name when the player picks their allegiance, recorded and executed on both client AND server (autochange). How do I fix this? Do I have to merge scripts with ‘MenuAccuScript’ ?

-- local script, within StarterPlayerScripts
-- called 'localteamch'

local repfirst = game:GetService('ReplicatedFirst') 
local repStorage = game:GetService('ReplicatedStorage')
local players = game:GetService('Players') 
local teams = game:GetService('Teams') 
local PAVN = teams:WaitForChild('PAVN') 
local ARVN = teams:WaitForChild('ARVN') 
local SPECTATOR = teams:WaitForChild('SPECTATOR') 

local AllegianceChanged = repfirst:WaitForChild('AllegianceChanged') 
local plr = players.LocalPlayer 
local menu2gui = repfirst.LoadingSequence:WaitForChild('Menu2Gui') 

menu2gui.ResetOnSpawn = false 
menu2gui.Parent = plr:WaitForChild("PlayerGui") 

local function showPicker() 
	if plr.Team == SPECTATOR then 
		menu2gui.Enabled = true 
	else 
		menu2gui.Enabled = false 
	end 
end 

showPicker() 

plr:GetPropertyChangedSignal('Team'):Connect(showPicker)

local SVNButton = menu2gui.backingfr.SouthVietN
local NVNButton = menu2gui.backingfr.NorthVietN

SVNButton.MouseButton1Click:Connect(function() 
	AllegianceChanged:FireServer(ARVN) 
end) 
NVNButton.MouseButton1Click:Connect(function() 
	AllegianceChanged:FireServer(PAVN) 
end)

-- regular script, within ServerScriptService
-- called 'TeamChanger'

local repStorage = game:GetService('ReplicatedStorage') 
local players = game:GetService('Players') 
local teams = game:GetService('Teams') 
local PAVN = teams:WaitForChild('PAVN') 
local ARVN = teams:WaitForChild('ARVN') 
local SPECTATOR = teams:WaitForChild('SPECTATOR') 
local chooseEvent = repStorage:WaitForChild('AllegianceChanged') 
local function onEvent(playerFrom, teamChosen) 
	if teamChosen == PAVN then 
		playerFrom.Team = PAVN 
	elseif teamChosen == ARVN then 
		playerFrom.Team = ARVN 
	else 
		playerFrom.Team = SPECTATOR
		if playerFrom.Character then 
			playerFrom.Character:Destroy() 
		end 
		return 
	end 
	playerFrom:LoadCharacter() 
end 
chooseEvent.OnServerEvent:Connect(onEvent)

-- within ReplicatedFirst, directly parented to LoadingSequence -> Menu2Gui (main menu ScreenGui), called MenuAccuScript

local MenuGui = script.Parent
local Player = MenuGui.Parent.Parent


MenuGui.Enabled = true

script.Parent.backingfr.NorthVietN.MouseButton1Click:Connect(function()
	Player.Team = game.Teams.PAVN
	script.Parent.backingfr.NorthVietN["Cartoon bubble button Sound"]:Play()
	local character = workspace:FindFirstChild(Player.Name)
    character.Humanoid.Health = 0
	MenuGui.Enabled = false

end)

script.Parent.backingfr.SouthVietN.MouseButton1Click:Connect(function()
	Player.Team = game.Teams.ARVN
	script.Parent.backingfr.SouthVietN["Cartoon bubble button Sound"]:Play()
	local character = workspace:FindFirstChild(Player.Name)
	character.Humanoid.Health = 0
	MenuGui.Enabled = false

end)
-- almost forgot about this one, this script is for the overhead gui itself in ServerScriptService
-- named 'teamindicatorrig'
local TeamIndicator = game.ReplicatedStorage:WaitForChild("TeamIndicator") 
game.Players.PlayerAdded:Connect(function(plr) 
	plr.CharacterAdded:Connect(function(character) 
		local TeamIndicatorClone = TeamIndicator:Clone() 
		TeamIndicatorClone.Parent = plr.Character.Head 
		TeamIndicatorClone.TextLabel.Text = plr.Team.Name 
		
	end) 
	plr.Changed:Connect(function() 
		game.Workspace:WaitForChild(plr.Name) 
		if plr.Character.Head:FindFirstChild("TeamIndicator") then 
			plr.Character.Head.TeamIndicator.TeamLabel.Text = plr.Team.Name 
		else 
			local TeamIndicatorClone = TeamIndicator:Clone() 
			TeamIndicatorClone.Parent = plr.Character.Head 
			TeamIndicatorClone.TextLabel.Text = plr.Team.Name 
		end 
	end) 
end)

please help.


for those who need the explorer hierarchy

There’s your problem.

Use a RemoteEvent and change the team on the server, as changes on the client do not replicate.

1 Like

I did use a RemoteEvent which I renamed to ‘AllegianceChanged’, yet it has no effect
Sorry for sounding like an idiot but I never understood events or how to use them in the first place

Can you draft a modified/fixed script?

Simply to add it, just do this:

script.Parent.backingfr.NorthVietN.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.AllegianceChanged:FireServer(true)
	--// Rest of logic, DO NOT CHANGE TEAM ON CLIENT
end)
script.Parent.backingfr.SouthVietN.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.AllegianceChanged:FireServer(false)
	--// Rest of logic, DO NOT CHANGE TEAM ON CLIENT
end)

And for the server:

game.ReplicatedStorage.AllegianceChanged.OnServerEvent:Connect(function(player, north)
	player.Team = north and game.Teams.PAVN or game.Teams.ARVN
end)

Simply sending through a boolean allows you to swap between 2 different teams, since sending it as false WILL result in the team being set to ARVN, and the opposite for sending true.

If you wanted to add more teams, you could swap out the logic for something like this:`

--// Client:
local teamToChangeTo = 1 --// Change this variable to change what team to set the player to.
game.ReplicatedStorage.AllegianceChanged:FireServer(teamToChangeTo)



--// Server:
local Teams = {
	[1] = game.Teams.Team1
	[2] = game.Teams.Team2
	[3] = game.Teams.Team3
}
game.ReplicatedStorage.AllegianceChanged.OnServerEvent:Connect(function(player, tNum)
	player.Team = Teams[tNum] or game.Teams.Team1
end

When using events, specifically from client to server (which is ESSENTIAL for anything changing players, such as health, names, teams etc), the first variable received on the server is ALWAYS the sender of the event, however you do not have to send this over from the client, as it is automatic.

I’m not going to go much into detail as I did link the article for RemoteEvents, so I’d highly suggest looking there so you don’t run into issues like this in the future.

Remember though, any and all modifications to anything in the game that must be replicated across clients MUST be done on at least somewhat the server.

For purely visual effects, I’d do Client > Server > Client. (Avoid lagging server with visual effects)

For damaging players, Client > Server. (All clients must replicate damage, so do it on the Server)

1 Like

New issue, now it bounces back to ‘SPECTATOR’ whenever the event is fired, forbidding me to join any team.



You’ve done a poor copy-paste job, and forgotten to delete the old event hook.

The server side should look like this:

local repStorage = game:GetService("ReplicatedStorage")
local teams = game:GetService("Teams")

local gameTeams = {
    [1] = teams.PAVN,
    [2] = teams.ARVN
    [3] = teams.SPECTATOR
}

game.ReplicatedStorage.AllegianceChanged.OnServerEvent:Connect(funcion(player, teamToChange)
    player.Team = gameTeams[teamToChange]
end

And here’s an update client-side, as you wrote that wrong, too.

--// To switch to PAVN team:
game.ReplicatedStorage.AllegianceChanged:FireServer(1)

--// To switch to ARVN
game.ReplicatedStorage.AllegianceChanged:FireServer(2)

--// To switch to spectator (if not automated)
game.ReplicatedStorage.AllegianceChanged:FireServer(3)

How to implement this little rewrite:

  1. Delete the section of server code in this screenshot and replace it with my server-side
  1. In the client, replace the event firing with what I’ve now supplied.
    The numbers being sent through are very important, as they fully determine what team the player will be put onto.

What you wrote wrong:

Server:

  • You had 2 different functions doing the exact same thing with one remote event, causing the team to swap twice, as each function had different logic.

Client:

  • You were only sending through true, which would end up in either button putting the player on the same team.

(I’ll also add that there may be some typos in the code I’ve provided here, not only have I written it in browser but my keyboard is also dying)

1 Like

team joined issue resolved but events still havent been fired, so it’s probably something wrong with the team indicator script itself that could be interfering or my spawn system

can you make a new test place for visual demonstration purposes?

works after all, seems like it was due to external script interferences in my devtest place that prevent the events necessary for the team switches to be fired (tested on a new workspace and it works normally)

it seems i may have to use external failsafe black-box spawns above or under to ensure the team switches are guaranteed - issue was fixed by simply activating the ‘AllowTeamChangeUponTouch’ property lol

so basically this means that if you use PlayerGuis to pick a team it will fire through the client but not the server, while if you simply toggle the aforementioned property the team switch WILL be recognized by the server

Is this supposed to be a studio bug? Because this would mean I would have to make the buttons automatically teleport the player character to their respective failsafe spawns, which would be a pain in the ahh to modify and include

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.