Advertisement
GaryScripts

Untitled

Apr 21st, 2020
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. --Variables
  2. local plrs = game:GetService("Players")
  3. local frame = script.Parent:WaitForChild("Frame")
  4. local slots = script.Parent.Frame:WaitForChild("Slots")
  5. local template = script.Parent.Frame:WaitForChild("Template")
  6.  
  7. local plr_table = {}
  8.  
  9. --Tween Variables
  10. local dir = "Out"
  11. local style = "Quart"
  12. local dur = 0.5
  13. local ovrr = true
  14. --Functions
  15.  
  16. local function clean(slot)
  17.     repeat --repeats this function until the slots X offset is equal to 400
  18.         wait()
  19.     until slot.Position.X.Offset == 400
  20.     slot:Destroy()
  21. end
  22.  
  23. local function remove(leaving)
  24.     if leaving then --checks to see if a player is leaving
  25.        
  26.         plr_table[leaving] = nil
  27.        
  28.         local slot = slots:FindFirstChild(leaving)
  29.         slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Offset), dir, style, dur, ovrr)
  30.        
  31.         local cour = coroutine.wrap(clean)
  32.         cour(slot)
  33.     end
  34. end
  35.  
  36.  
  37. local function add()
  38.     local children = plrs:GetChildren() --Gets the children from the players service
  39.     for c = 1, #children do --loops
  40.         if plr_table[children[c].Name] == nil then --Sees if the name has no value
  41.             plr_table[children[c].Name] = 1 -- Creates slot
  42.            
  43.             local slot = template:Clone() --Makes a variable that clones the template
  44.            
  45.             slot.Name = children[c].Name --Sets the properties of the local variable "slot"
  46.             slot.Text = slot.Name
  47.             slot.Parent = slots
  48.         end
  49.     end
  50. end
  51.  
  52. local function adjust(leaving)
  53.     add()
  54.     remove(leaving)
  55.    
  56.     local count = 0
  57.    
  58.     for key, value in pairs(plr_table) do
  59.         count = count + 1
  60.         local slot = slots:FindFirstChild(key)
  61.         local yPos = 30 + (25+2) * (count-1)
  62.         slot:TweenPosition(UDim2.new(0,0,0,yPos),dir,style,dur,ovrr)
  63.     end
  64. end
  65.  
  66. --Events
  67. plrs.PlayerAdded:Connect(function()
  68.     adjust(nil)
  69. end)
  70.  
  71. plrs.PlayerRemoving:Connect(function(leaving)
  72.     adjust(leaving.Name)
  73. end)
  74.  
  75. --Setup
  76. adjust()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement