Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- local plrs = game:GetService("Players")
- local frame = script.Parent:WaitForChild("Frame")
- local slots = script.Parent.Frame:WaitForChild("Slots")
- local template = script.Parent.Frame:WaitForChild("Template")
- local plr_table = {}
- --Tween Variables
- local dir = "Out"
- local style = "Quart"
- local dur = 0.5
- local ovrr = true
- --Functions
- local function clean(slot)
- repeat --repeats this function until the slots X offset is equal to 400
- wait()
- until slot.Position.X.Offset == 400
- slot:Destroy()
- end
- local function remove(leaving)
- if leaving then --checks to see if a player is leaving
- plr_table[leaving] = nil
- local slot = slots:FindFirstChild(leaving)
- slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Offset), dir, style, dur, ovrr)
- local cour = coroutine.wrap(clean)
- cour(slot)
- end
- end
- local function add()
- local children = plrs:GetChildren() --Gets the children from the players service
- for c = 1, #children do --loops
- if plr_table[children[c].Name] == nil then --Sees if the name has no value
- plr_table[children[c].Name] = 1 -- Creates slot
- local slot = template:Clone() --Makes a variable that clones the template
- slot.Name = children[c].Name --Sets the properties of the local variable "slot"
- slot.Text = slot.Name
- slot.Parent = slots
- end
- end
- end
- local function adjust(leaving)
- add()
- remove(leaving)
- local count = 0
- for key, value in pairs(plr_table) do
- count = count + 1
- local slot = slots:FindFirstChild(key)
- local yPos = 30 + (25+2) * (count-1)
- slot:TweenPosition(UDim2.new(0,0,0,yPos),dir,style,dur,ovrr)
- end
- end
- --Events
- plrs.PlayerAdded:Connect(function()
- adjust(nil)
- end)
- plrs.PlayerRemoving:Connect(function(leaving)
- adjust(leaving.Name)
- end)
- --Setup
- adjust()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement