LocalScript, Parent playerList(ScreenGui):
--< variables
local players = game:GetService("Players")
local frame = script.Parent.Frame
local slots = frame.slots
local temp = frame.Template
local players_table = {}
--< tween info:TweenPosition(endPosition, EasingDirection, EasingStyle, Time, Override)
local dir = "Out"
local style = "Quad"
local dur = 0.5
--< functions
local function cleanup(slot)
-- repeat wait until the slot finishes tweening
repeat
wait()
until slot.Position.X.Offset == 400
slot:Destroy()
end
local function remove(leaving)
-- check if a player is leaving
if leaving then
-- if so, delete dictionary entry
players_table[leaving] = nil
-- tween players slot out
local slot = slots:FindFirstChild(leaving)
slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Off), dir, style, dur, true)
-- delete the slot once it finishes (coroutine)
local cor = coroutine.wrap(cleanup)
cor(slot)
end
end
local function add()
-- loop through players
local chil = players:GetChildren()
for c = 1, #chil do
-- check if present in dictionary
if players_table[chil[c].Name] == nil then
-- add to dictionary
players_table[chil[c].Name] = 1
-- create a slot in the list
local slot = temp:Clone()
-- edit this slot
slot.Name = chil[c].Name
slot.Text = slot.Name
slot.Parent = slots
end
end
end
local function adjust(leaving)
-- add() and remove()
add()
remove(leaving)
local count = 0
-- loop through players_table
for key, value in pairs(players_table) do
count = count + 1
-- find corresponding slots
local slot = slots:FindFirstChild(key)
-- tween slot positions
local ypos = 30 + (25+2)*(count-1)
slot:TweenPosition(UDim2.new(0, 0, 0, ypos), dir, style, dur, true)
end
end
--< events
-- player added event
players.PlayerAdded:connect(function()
adjust()
end)
-- player removing event
players.PlayerRemoving:connect(function(leaving)
adjust(leaving.Name)
end)
--< setup
adjust()
playerList's children: LocalScript and Frame. Frame's children: slots(Folder), Template(TextLabel), TextLabel any fixes?
If so, answer me with the answer tool, not the comments, if not don't answer. :)
-Skepticalitys
The video tutorial I got the LocalScript in:
This
LocalScriptusesTweeningif that helps.
