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?)
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
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)
for i, v in pairs(game.Teams:GetChildren()) do
v.PlayerAdded:Connect(function(player)
player.PlayerGui.OverheadGUI.PlayerTeam.Text = player.Team.Name
end)
end