So I have a script that displays your rank and team over head like so: http://gyazo.com/129a61be0c99be640f8da91400f510ae
Only problem is when someone is on the other team and leaves that team, the team goes away and doesn't come back. https://gyazo.com/955800a327ba68162951b951fd54cd69]https://gyazo.com/955800a327ba68162951b951fd54cd69 https://gyazo.com/66c44b785c803845f4d9e7f39215f799]https://gyazo.com/66c44b785c803845f4d9e7f39215f799[](http://)
And if that person were to rejoin they would be on the "neutral" team.
I know it must have something to do with this script because when I play it without the script it works fine and the team doesn't delete. Would anyone mind looking over the code and telling me what I can do to fix it? I don't have much experience in scripting.
--FORMAT {teamname, team color,groupId/{names}, payout,{tools},{cars}}
local teams = {
-- SPECIAL TEAMS --
{"U.S. Marshal Service" ,"Deep blue", 977773, 0,{},{}},
{"Americans" ,"Forest green", 758071, 0,{},{}},
}
local offset = 9657
local AoSTabs = {["AoS Players"] = {}, ["AoS Groups"] = {}}
local mathCeil = math.ceil
local stringMatch = string.match
local stringSub = string.sub
local stringFind = string.find
local stringGsub = string.gsub
local stringLen = string.len
local stringGmatch = string.gmatch
local tableInsert = table.insert
local tableRemove = table.remove
function getToolTab(teamName)
for _,v in pairs(teams) do
if teamName == v[1] then
return v[5]
end
end
end
spawn(function()
while true do
wait(30)
pcall(function()
end)
end
end)
function isAdmin(name)
return false
end
function checkToAdd(team)
for _,v in pairs(game:GetService("Teams"):GetTeams()) do
if v.TeamColor == team then return end
end
for _,getTeam in pairs(teams) do
if getTeam[2] == team.Name then
local newTeam = Instance.new("Team")
newTeam.AutoColorCharacters = false
newTeam.AutoAssignable = false
newTeam.Name = getTeam[1]
newTeam.TeamColor = team
newTeam.Parent = game.Teams
break
end
end
end
_G.checkToAdd = checkToAdd
function checkToRemove()
for _,teams in pairs(game.Teams:GetTeams()) do
local hasPeople = false
for _,v in pairs(game.Players:GetPlayers()) do
if v.TeamColor == teams.TeamColor then
hasPeople = true
break
end
end
if not hasPeople then
teams:Destroy()
end
end
end
_G.checkToRemove = checkToRemove
function fromCSV(s)
s = stringSub(s,2)
local t = {} -- table to collect fields
local fieldstart = 1
repeat
-- next field is quoted? (start with `"'?)
if stringFind(s, '^"', fieldstart) then
local a, c
local i = fieldstart
repeat
-- find closing quote
a, i, c = stringFind(s, '"("?)', i+1)
until c ~= '"' -- quote not followed by quote?
if not i then error('unmatched "') end
local f = stringSub(s, fieldstart+1, i-1)
tableInsert(t, (stringGsub(f, '""', '"')))
fieldstart = stringFind(s, ',', i) + 1
else -- unquoted; find next comma
local nexti = stringFind(s, ',', fieldstart)
if nexti ~= nil then
tableInsert(t, stringSub(s, fieldstart, nexti-1))
fieldstart = nexti + 1
end
end
until fieldstart > stringLen(s)
return t
end
function isInTable(tab,val)
for _,v in pairs(tab) do
if v == val then
return true
end
end
return false
end
function isInGroupList(tab, player)
for _,v in pairs(tab) do
pcall(function()
if player:IsInGroup(v) then
return true
end
end)
end
return false
end
function isAoS(player)
if isInTable(AoSTabs["AoS Players"], tostring(player.userId)) or isInGroupList(AoSTabs["AoS Groups"], player) then
return "AoS - "
else
return ""
end
end
function updateRank(p, playerStorage)
local rankGui = p.Character:FindFirstChild("RankGui") and p.Character.RankGui or game.ServerStorage.Guis.RankGui:clone()
rankGui.Parent = p.Character
rankGui.Rank.PlayerName.Text = p.Name
rankGui.Adornee = p.Character.Head
for _,v in pairs(teams) do
if v[2] == p.TeamColor.Name then
rankGui.Rank.PlayerName.TextColor = BrickColor.new(v[2])
if v[2] == "White" or v[2] == "Institutional white" or v[2] == "Mid gray" then
rankGui.Rank.PlayerName.TextStrokeTransparency = 1
else
rankGui.Rank.PlayerName.TextStrokeTransparency = 0
end
local startText = isAoS(p)
if (type(v[3]) == "table") or (type(v[3]) == "string") then
rankGui.Rank.PlayerTitle.Text = startText..v[1]
elseif v[3] ~= 0 then
local role = p:GetRoleInGroup(v[3])
rankGui.Rank.PlayerTitle.Text = startText..role
elseif p.TeamColor.Name == "Deep orange" then
rankGui.Rank.PlayerTitle.Text = startText.."Inmate"
else
rankGui.Rank.PlayerTitle.Text = startText.."Visitor"
end
end
end
end
_G.updateRank = updateRank
function setupCharacter(p,char, playerStorage)
p:WaitForChild("PlayerGui")
updateRank(p, playerStorage)
end
function setupPlayer(p)
local playerStorage = game:GetService("DataStoreService"):GetDataStore(tostring(p.userId))
if p.Character then
setupCharacter(p,p.Character, playerStorage)
end
p.CharacterAdded:connect(function(char)
setupCharacter(p,char, playerStorage)
end)
end
game.Players.PlayerAdded:connect(function(p)
setupPlayer(p)
end)
for _,v in pairs(game.Players:GetPlayers()) do
setupPlayer(v)
end
game.Players.PlayerRemoving:connect(function(p)
local uid = tostring(p.userId)
checkToRemove()
end)
wait(5)

2 comments
btw you didnt paste the links right so we cant click on them
gyazo link not working