CCCPaste Login

ai test

local Players = game:GetService("Players")
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "PlayerListScreen"
ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local PlayerListFrame = Instance.new("Frame")
PlayerListFrame.Name = "PlayerListFrame"
PlayerListFrame.Size = UDim2.new(0.8, 0, 0, 0)
PlayerListFrame.Position = UDim2.new(0.1, 0, 0, 0)
PlayerListFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2) -- Dark grey background
PlayerListFrame.BorderSizePixel = 0
PlayerListFrame.Parent = ScreenGui

local PlayerListTextBox = Instance.new("TextBox")
PlayerListTextBox.Size = UDim2.new(1, 0, 0, 0)
PlayerListTextBox.SizeConstraints = UDim2.new(1, 0, 0, 0)
PlayerListTextBox.Multiline = true
PlayerListTextBox.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3) -- Slightly lighter background
PlayerListTextBox.BorderSizePixel = 0
PlayerListTextBox.Parent = PlayerListFrame

-- Function to update the player list
local function UpdatePlayerList()
    local playerList = ""
    for i, player in pairs(Players:GetPlayers()) do
        local playerName = player.Name
        local playerGui = player.PlayerGui
        if playerGui then
            local playerListButton = playerListButton
            playerListButton.BackgroundColor3 = Color3.new(1, 1, 1) -- Highlight when hovered
            local playerListButton = Instance.new("TextButton")
            playerListButton.Size = UDim2.new(0.8, 0, 0, 0)
            playerListButton.Position = UDim2.new(0.1, 0, 0, 0)
            playerListButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
            playerListButton.BorderSizePixel = 0
            playerListButton.Text = playerName
            playerListButton.Parent = PlayerListFrame
            playerListButton.Size = UDim2.new(0.8, 0, 0, 0)
            playerListButton.Position = UDim2.new(0.1, 0, 0, 0)
            playerListButton.BorderSizePixel = 0
            playerListButton.Text = playerName
            playerListButton.Parent = PlayerListFrame
            playerListButton.Size = UDim2.new(0.8, 0, 0, 0)
            playerListButton.Position = UDim2.new(0.1, 0, 0, 0)
            playerListButton.BorderSizePixel = 0
            playerListButton.Text = playerName
            playerListButton.Parent = PlayerListFrame

            if playerList == "" then
                playerList = playerName
            else
                playerList = playerList .. ", " .. playerName
            }
        end
    end

    PlayerListTextBox.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    PlayerListTextBox.Text = "Players: " .. playerList

    -- Clean up the buttons to prevent memory leaks
    for i, button in pairs(PlayerListFrame.Children) do
        if button:IsA("TextButton") then
            button:Destroy()
        end
    end
end

-- Call the function to update the list initially
UpdatePlayerList()

-- Event listener for when the player clicks on a button
PlayerListFrame.UserAdded:Connect(function(player)
    -- Update the list when a player joins
    UpdatePlayerList()
end)

-- Event listener for when the player leaves the server
Players.PlayerDropped:Connect(function(player)
    -- Update the list when a player leaves
    UpdatePlayerList()
end)