local frame = script.Parent
frame.Cancel.MouseButton1Click:Connect(function()
frame.Visible = false
end)
frame.Kick.MouseButton1Click:Connect(function()
if game.Players:FindFirstChild(frame.Player.Text) then
game.ReplicatedStorage.KickPlayer:FireServer(frame.Player.Text, frame.Reason.Text)
end
end)
Link it to a PlayerAdded to add players when they joined to add a player to the list and then a PlayerRemoving when they leave the game to remove them from the list
local Players = game:GetService("Players")
local username = script.Parent.Parent.Player
local function OnPlayer(Player)
local template = Instance.new("TextButton")
template.Name = Player.Name
template.BorderSizePixel = 0
template.Font = Enum.Font.SourceSansBold
template.Parent = script.Parent
template.Size = UDim2.new(0, 319,0, 28)
template.BackgroundColor3 = Color3.new(0.368627, 0.368627, 0.368627)
template.Text = Player.Name
template.TextColor3 = Color3.new(1, 1, 1)
template.TextScaled = true
template.MouseButton1Click:Connect(function()
username.Text = template.Name
end)
end
-- run OnPlayer function on everyone already in game
for _, Player in pairs(Players:GetPlayers())do
OnPlayer(Player)
end
-- and also run it on players who join the game later
Players.PlayerAdded:Connect(OnPlayer)
-- on player removing
Players.PlayerRemoving:Connect(function(Player)
-- try to find the template with the name of the player who is getting removed
local template = script.Parent:FindFirstChild(Player.Name)
-- if template exists then delete template
if template then
template:Destroy()
end
end)