HowToRoblox

ButtonsHandler

Jun 14th, 2021 (edited)
2,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local frame = script.Parent
  2. frame.Draggable, frame.Active = true, true
  3.  
  4. local plrList = frame:WaitForChild("PlayerList")
  5.  
  6.  
  7. local plrChosen = nil
  8.  
  9.  
  10. function updatePlayers()
  11.    
  12.     for i, child in pairs(plrList:GetChildren()) do
  13.        
  14.         if child:IsA("TextButton") then child:Destroy() end
  15.     end
  16.    
  17.    
  18.     for i, plr in pairs(game.Players:GetPlayers()) do
  19.        
  20.         local button = script.PlayerName:Clone()
  21.        
  22.         button.Text = plr.Name
  23.        
  24.         button.Parent = plrList
  25.        
  26.        
  27.         if plrChosen == plr then
  28.             button.BackgroundColor3 = Color3.fromRGB(213, 212, 202)
  29.         end
  30.        
  31.        
  32.         button.MouseButton1Click:Connect(function()
  33.            
  34.             plrChosen = plr
  35.            
  36.             for i, child in pairs(plrList:GetChildren()) do
  37.                
  38.                 if child:IsA("TextButton") then child.BackgroundColor3 = Color3.fromRGB(252, 250, 239) end
  39.             end
  40.            
  41.             button.BackgroundColor3 = Color3.fromRGB(213, 212, 202)
  42.         end)
  43.     end
  44. end
  45.  
  46. updatePlayers()
  47. game.Players.PlayerAdded:Connect(updatePlayers)
  48. game.Players.PlayerRemoving:Connect(updatePlayers)
  49.  
  50.  
  51.  
  52. for i, child in pairs(frame:GetChildren()) do
  53.    
  54.     if child:IsA("TextButton") then
  55.        
  56.        
  57.         child.MouseButton1Click:Connect(function()
  58.            
  59.             game.ReplicatedStorage.AdminClicked:FireServer(plrChosen, child.Name)
  60.         end)
  61.     end
  62. end
Add Comment
Please, Sign In to add comment