Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Local Script
- -- Variables
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- local Gui = Instance.new("ScreenGui", Player.PlayerGui)
- local PlayerListFrame = Instance.new("Frame", Gui)
- local MessageTextBox = Instance.new("TextBox", PlayerListFrame)
- local SendMessageButton = Instance.new("TextButton", PlayerListFrame)
- -- UI Properties
- Gui.Name = "MessageGui"
- PlayerListFrame.Size = UDim2.new(0.3, 0, 0.5, 0)
- PlayerListFrame.Position = UDim2.new(0.35, 0, 0.25, 0)
- PlayerListFrame.BackgroundTransparency = 0.3
- MessageTextBox.Size = UDim2.new(0.8, 0, 0.1, 0)
- MessageTextBox.Position = UDim2.new(0.1, 0, 0.8, 0)
- MessageTextBox.PlaceholderText = "Enter message (max 20 chars)"
- MessageTextBox.Text = ""
- SendMessageButton.Size = UDim2.new(0.8, 0, 0.1, 0)
- SendMessageButton.Position = UDim2.new(0.1, 0, 0.9, 0)
- SendMessageButton.Text = "Send Message"
- -- Create a list of players
- local function updatePlayerList()
- for _, v in pairs(PlayerListFrame:GetChildren()) do
- if v:IsA("TextButton") and v ~= SendMessageButton then
- v:Destroy()
- end
- end
- local yPosition = 0
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= Player then
- local PlayerButton = Instance.new("TextButton", PlayerListFrame)
- PlayerButton.Size = UDim2.new(0.8, 0, 0.1, 0)
- PlayerButton.Position = UDim2.new(0.1, 0, yPosition, 0)
- PlayerButton.Text = player.Name
- PlayerButton.MouseButton1Click:Connect(function()
- sendMessage(player)
- end)
- yPosition = yPosition + 0.1
- end
- end
- end
- -- Function to send message
- local function sendMessage(targetPlayer)
- if #MessageTextBox.Text <= 20 and #MessageTextBox.Text > 0 then
- local MessageGui = Instance.new("ScreenGui", targetPlayer.PlayerGui)
- local MessageLabel = Instance.new("TextLabel", MessageGui)
- MessageGui.Name = "PopupMessage"
- MessageLabel.Size = UDim2.new(0.8, 0, 0.1, 0)
- MessageLabel.Position = UDim2.new(0.1, 0, 0.45, 0)
- MessageLabel.Text = MessageTextBox.Text
- MessageLabel.TextScaled = true
- MessageLabel.BackgroundTransparency = 0.5
- wait(50)
- MessageGui:Destroy()
- end
- end
- -- Events
- SendMessageButton.MouseButton1Click:Connect(function()
- if MessageTextBox.Text and #MessageTextBox.Text <= 20 then
- for _, playerButton in pairs(PlayerListFrame:GetChildren()) do
- if playerButton:IsA("TextButton") and playerButton ~= SendMessageButton then
- playerButton.MouseButton1Click:Connect(function()
- local targetPlayer = Players:FindFirstChild(playerButton.Text)
- if targetPlayer then
- sendMessage(targetPlayer)
- end
- end)
- end
- end
- else
- warn("Message must be 20 characters or less!")
- end
- end)
- Players.PlayerAdded:Connect(updatePlayerList)
- Players.PlayerRemoving:Connect(updatePlayerList)
- -- Initialize player list
- updatePlayerList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement