HowToRoblox

GuiHandler

Jan 24th, 2021
960
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function updateGui()
  2.    
  3.    
  4.     local serverFrames = {}
  5.    
  6.    
  7.     for i, serverValue in pairs(game.ReplicatedStorage.Servers:GetChildren()) do
  8.        
  9.         local name = serverValue.Name
  10.        
  11.         local serverStats = string.split(serverValue.Value, " ")
  12.        
  13.         local id = serverStats[1]
  14.         local plrs = serverStats[2]
  15.        
  16.        
  17.         local serverFrame = script.ServerTemplate:Clone()
  18.        
  19.         serverFrame:WaitForChild("ServerName").Text = name .. "\n ID: " .. id
  20.         serverFrame:WaitForChild("Players").Text = plrs .. "/" .. game.Players.MaxPlayers
  21.        
  22.        
  23.         table.insert(serverFrames, serverFrame)
  24.        
  25.  
  26.         serverFrame.JoinButton.MouseButton1Click:Connect(function()
  27.                
  28.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, id)
  29.         end)
  30.  
  31.        
  32.         script.Parent.List:ClearAllChildren()
  33.  
  34.         script.UIListLayout:Clone().Parent = script.Parent.List
  35.        
  36.        
  37.         for i, serverFrame in pairs(serverFrames) do
  38.            
  39.             serverFrame.Parent = script.Parent.List
  40.         end
  41.     end
  42. end
  43.  
  44.  
  45. updateGui()
  46.  
  47. game.ReplicatedStorage.Servers.ChildAdded:Connect(updateGui)
  48. game.ReplicatedStorage.Servers.ChildRemoved:Connect(updateGui)
RAW Paste Data