OverheadGUI - Team synchronization

Hi. I’m a beginner scripter in Roblox Studio and I don’t know exactly how to fix something, that’s why I’m asking here. What I mean is that I don’t know how to synchronize the team name on overheadgui, because when changing it, only the one that I previously marked as “AutoAssignable” is displayed (if I don’t mark autoassigable, an error will appear in the output but I know the reason because I didn’t include “else” ). I haven’t found a guide that would help me yet. If anyone would like to help me with this, I would like them to explain it to me quite thoroughly, because, as I wrote, I am a beginner.

Script:

local Players = game:GetService("Players")

local teamTag = game.ReplicatedStorage.PlayerActions.TeamChange

local connections = {}
local overHeadTemplate = script.OverheadGUI

Players.PlayerAdded:Connect(function(player)
	connections[player] = player.CharacterAdded:Connect(function(character)
		local newOverHead = overHeadTemplate:Clone()

		newOverHead.PlayerName.Text = player.Name
		newOverHead.PlayerTeam.Text = player.Team.Name

		newOverHead.Parent = character.Head
	end)
end)

Players.PlayerRemoving:Connect(function(player)
	if connections[player] then
		connections[player]:Disconnect()
		connections[player] = nil
	end
end)

looking at the script… you can’t really disconnect a player from a table
tell me what are you trying to do “in a nutshell”
(i assume, make an overhead gui that displays the player’s team?)

I’m making overheadgui that will display player name and player team (The team will synchronize when changed but I don’t know how to make it)

you’re lucky i got an overhead gui in my roblox files folder, hollon i gotta find it first

I added the rank from groupId and it looks like that
image_2024-03-12_092902805

found it; not made by me, all creds to original creator
overheadgui.rbxm (12.0 KB)

  • place the script inside ServerScriptService
  • on line 26, change 7 to your group ID

Bro, thanks for that but that’s not what I wanted. I included that I just need help with scripting the team text (textlabel in overheadgui) synchronization

then erase the script and replace it with the following:

local Players = game:GetService("Players")
local overHeadTemplate = script.OverheadGUI

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local newOverHead = overHeadTemplate:Clone()
		newOverHead.PlayerName.Text = player.Name
		newOverHead.PlayerTeam.Text = player.Team.Name

		newOverHead.Parent = character.Head
	end)
end)

game.Teams.PlayerAdded:Connect(function(player)
	player.PlayerGui.nameOfTheGui.PlayerTeam.Text = player.Team.Name
end)

side note: don’t use ai for script generation, it genuinely sucks

PlayerAdded is not a valid member of Teams “Teams”

ServerScriptService.OverheadGUIScript:13: attempt to index nil with ‘Name’.

I didn’t use AI. I was watching a tutorial but there wasn’t anything about “team synchro” so.

Script:

local Players = game:GetService("Players")

local rankInformation = require(script.RankInformation)

local connections = {}
local overHeadTemplate = script.OverheadGUI

Players.PlayerAdded:Connect(function(player)
	connections[player] = player.CharacterAdded:Connect(function(character)
		local newOverHead = overHeadTemplate:Clone()

		newOverHead.PlayerName.Text = player.Name
		newOverHead.PlayerTeam.Text = player.Team.Name
		
		for _, info in pairs (rankInformation) do
			local isPlayerInDivision = player:IsInGroup(info.groupId)
			
			if isPlayerInDivision then
				newOverHead.PlayerRank.TextColor3 = info.color
				newOverHead.PlayerRank.Text = "<i>".. player:GetRoleInGroup(info.groupId) .."</i>"
			end
		end

		newOverHead.Parent = character.Head
	end)
end)

game.Teams.PlayerAdded:Connect(function(player)
	player.PlayerGui.OverheadGUI.PlayerTeam.Text = player.Team.Name
end)

Players.PlayerRemoving:Connect(function(player)
	if connections[player] then
		connections[player]:Disconnect()
		connections[player] = nil
	end
end)

PlayerAdded is not a valid member of Teams “Teams”

pardon, mistook it for this:

try this:

for i, v in pairs(game.Teams:GetChildren()) do
	v.PlayerAdded:Connect(function(player)
		player.PlayerGui.OverheadGUI.PlayerTeam.Text = player.Team.Name
	end)
end

ServerScriptService.OverheadGUIScript:13: attempt to index nil with ‘Name’ - Server - OverheadGUIScript:13
image_2024-03-12_095751457

do any teams exist yet?
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

yeah,
image_2024-03-12_100115730

select a random team, and change AutoAssignable to true


It works but the output is showing an error.
image_2024-03-12_100413232

use :WaitForChild() on the OverheadGUI

seems like i can’t reply now lol


not :FindFirstChild, but :WaitForChild()

Oops, sorry. I changed it and it shows that: Infinite yield possible on ‘Players.NXT5V.PlayerGui:WaitForChild(“OverheadGUI”)’ - Studio

instead of PlayerGui do character.Head:Wait for child blah blah blah