I am currently trying to achieve a function that would keep an updated list of alive players.
Are there any tips performance-wise that would help improve the code snip?
local function StartUp()
local function CharLister(Child, State)
if State == "Added" then
table.insert(CharList, Child)
elseif State == "Removed" then
for i = 1, #CharList do
if CharList[i].Name == Child.Name then
table.remove (CharList, i)
end
end
end
end
local function CharAdded(Char)
CharLister(Char, "Added")
end
local function CharRemoved(Char)
CharLister(Char, "Removed")
end
local function PlrAdded(Plr)
Plr.CharacterAdded:Connect(CharAdded)
Plr.CharacterRemoving:Connect(CharRemoved)
end
Players.PlayerAdded:Connect(PlrAdded)
for i, Plr in pairs(Players:GetChildren()) do
PlrAdded(Plr)
if not Plr.Character then
Plr.CharacterAdded:wait()
CharAdded(Plr.Character)
else
CharAdded(Plr.Character)
end
end
end