When Player Changes Team It Changes Other Players Overhead Tag

  1. What do you want to achieve?
    I want to fix a bug with my overhead tag script.

  2. What is the issue?
    The issue is that I have an overhead team tag that displays the player team, when the player uses the team switch GUI it does switch their team but the overhead tag is not changed on their character but instead on the most recently joined player.

  3. What solutions have you tried so far?
    I don’t really know what the problem is so I don’t know where to start looking for solutions.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local lesbianClickEvent = ReplicatedStorage:WaitForChild("LesbianEvent")
local transgenderClickEvent = ReplicatedStorage:WaitForChild("TransgenderEvent")
local gayClickEvent = ReplicatedStorage:WaitForChild("GayEvent")
local biClickEvent = ReplicatedStorage:WaitForChild("BisexualEvent")
local asClickEvent = ReplicatedStorage:WaitForChild("AsexualEvent")
local panClickEvent = ReplicatedStorage:WaitForChild("PanEvent")
local straightClickEvent = ReplicatedStorage:WaitForChild("StraightEvent")
local otherClickEvent = ReplicatedStorage:WaitForChild("OtherEvent")


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		teamOverheadClone = game.ReplicatedStorage.OverheadGui:Clone()
		teamOverheadClone.Parent = Character.Head
		
		teamInfo = teamOverheadClone.Team
			
		local PlayerTeam = Player.Team.Name
			
		teamInfo.Text = PlayerTeam
		teamOverheadClone.Team.TextColor3 = Player.TeamColor.Color
		
		

	end)
end)

local function lesbianTeam(Player)
	teamInfo.Text = 'Lesbian'
	teamOverheadClone.Team.TextColor3 = game.Teams.Lesbian.TeamColor.Color
	Player.Team = game.Teams.Lesbian
end

local function transgenderTeam(Player)
	teamInfo.Text = 'Transgender'
	teamOverheadClone.Team.TextColor3 = game.Teams.Transgender.TeamColor.Color
	Player.Team = game.Teams.Transgender
end

local function gayTeam(Player)
	teamInfo.Text = 'Gay'
	teamOverheadClone.Team.TextColor3 = game.Teams.Gay.TeamColor.Color
	Player.Team = game.Teams.Gay
end

local function biTeam(Player)
	teamInfo.Text = 'Bisexual'
	teamOverheadClone.Team.TextColor3 = game.Teams.Bisexual.TeamColor.Color
	Player.Team = game.Teams.Bisexual
end

local function aSexualTeam(Player)
	teamInfo.Text = 'Asexual'
	teamOverheadClone.Team.TextColor3 = game.Teams.Asexual.TeamColor.Color
	Player.Team = game.Teams.Asexual
end

local function panSexualTeam(Player)
	teamInfo.Text = 'Pansexual'
	teamOverheadClone.Team.TextColor3 = game.Teams.Pansexual.TeamColor.Color
	Player.Team = game.Teams.Pansexual
end

local function StraightTeam(Player)
	teamInfo.Text = 'Straight'
	teamOverheadClone.Team.TextColor3 = game.Teams.Straight.TeamColor.Color
	Player.Team = game.Teams.Straight
end

local function otherTeam(Player)
	teamInfo.Text = 'Other'
	teamOverheadClone.Team.TextColor3 = game.Teams.Other.TeamColor.Color
	Player.Team = game.Teams.Other
end

lesbianClickEvent.OnServerEvent:Connect(lesbianTeam)
transgenderClickEvent.OnServerEvent:Connect(transgenderTeam)
gayClickEvent.OnServerEvent:Connect(gayTeam)
biClickEvent.OnServerEvent:Connect(biTeam)
asClickEvent.OnServerEvent:Connect(aSexualTeam)
panClickEvent.OnServerEvent:Connect(panSexualTeam)
straightClickEvent.OnServerEvent:Connect(StraightTeam)
otherClickEvent.OnServerEvent:Connect(otherTeam)

If anyone could help me it would be appreciated :slight_smile:

1 Like

What is teamInfo? I can’t see at the code. Is it the text at the tag?

2 Likes

Ill show you a little bit better way, this is an example:

LocalScript > Under your gui

local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer

local remoteEvent = replicatedStorage.remoteEvent
local teamButtons

-- you can make 1 event for all the buttons instead of creating different for every team
for k, v in ipairs(teamButtons:GetChildren()) do
	remoteEvent:FireServer(v.Name) -- giving server the button name which will be the name of the team
end

Script > ServerScriptService

local players = game:GetService("Players")
local teams = game:GetService("Teams")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.remoteEvent
local nameTag

players.PlayerAdded:Connect(function(player)
	player.Team = teams.Default
	
	player.CharacterAdded:Connect(function()
		local tag = nameTag:Clone()
		tag.TextLabel.Text = player.Team.Name
	end)
	-- the function below will be called when the player team change
	player:GetPropertyChangedSignal("Team"):Connect(function()
                if not player.Character then return end
		local head = player.Character:FindFirstChild("Head")
		if not head then return end
		local tag = head:FindFirstChild("Tag")
		if not tag then return end
		if tag then
			tag.TextLabel.Text = player.Team.Name
		end
	end)
end)
-- listening for the event from client which will give us the teamName
remoteEvent.OnServerEvent:Connect(function(player, teamName)
	local team = teams:FindFirstChild(teamName)
	if team then
		player.Team = team
	end
end)
1 Like

Hi, I am a little bit confused about the local script part for the buttons, how do I make it so it detects the buttons? Sorry if it’s an obvious question.

Yeah the team info is the text for the tag.

i sent you the code above:

local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer

local remoteEvent = replicatedStorage.remoteEvent
local teamButtons -- this should be an folder where you store your "Team Buttons"

-- now we are looping through all the children of the folder, so through every button
for k, v in ipairs(teamButtons:GetChildren()) do
	remoteEvent:FireServer(v.Name) -- giving server the button name which will be the name of the team
end