Player Kick System

So i’m trying to make a Player list where i can click on their name it automatically kicks you out.

1 Like

So For the Player List Should i use it a template format or should i use a Script to customize the buttons background and all.

Here’s a guidance list to get you started.

1. Make a Player UI of your own Customization
2. Add Button Frames somewhere (make sure the player name text is there)
3. In the Button(s), add local script to kick (getting player from game.Players, plr:Kick()
4. Testing should be done from there

I’m Confused, i was told you can’t kick a different player from a local script?

I’m pretty sure it works on both sides, but you have to be careful because of the Exploiters.

I was going to do a While true loop to Look through all the players in the game.

Don’t worry about it being Exploited, i’m just worried my Moderators will abuse it.

So here’s what you should do in my opinion assuming this leaderboard has already been scripted on your end:

P.S. If you kick on the client side they will only be gone for that one person and it may mess up some of your scripts. Dont do that.

  1. Setup a remoteevent for the arguments :FireServer(plr, plrbeingkicked)
    With the first argument being the localplayer and 2nd being the person who you want to kick
  2. Have the remote check if the user who fired the remote (plr) is a staff member
  3. You need to link this to your leaderboard

So the thing i’m trying to make is a Player list. Like Roblox Player list where you can click on a player, but it being where it kicks the player when the button is clicked

I have the whole kick system done just not the player list

If its a player list where if you click the button, it kicks people, I have no idea why people are recommending remote events, instead, use 1 server script and do

button.MouseButton1Click:Connect(function()
    local target = --define the target
    target:Kick()
end)

For those who don’t know, server scripts work perfectly fine with buttons too.

Then to get this accomplished you would need to redo the roblox leaderboard by checking their CoreGui code, other than this you cannot access the PlayerList since it is not within your PlayerGui.

image

hmm to give an example of what I’m tryinf to achieve is the player list that Arsenal has for their Private server menu

What i’m trying to do is this where it automaticly puts the player’s username in a textbutton and if i click o the text button.

Another Example is this

1 Like

Then I suggest code like this:

local frame = --frame which holds the buttons

function kick(button)
    button.MouseButton1Click:Connect(function()
        local plr = game.Players[button.Text]
        plr:Kick()
    end)
end

for i,v in pairs(frame:GetChildren()) do
    kick(v)
end

frame.ChildAdded:Connect(kick)
1 Like

but, how would that work. because i’m trying to loop through teh characters

I Also Suggest Using A Remote Event For Kicking.

Hence, your Local Script (Client) Should Look like This.

local Remote = game.ReplicatedStorage.RemoteEvent -- Define the Remote Event Inside Replicated Storage
local childrenFrame = -- Define the Frame which Consists of The Kick Buttons

function onKick(button) -- Create A function
   Remote:FireServer(button.Text) -- Fire the Remote with Variable Text
end

local debounce = false -- A variable to Prevent Button Spam

childrenFrame.ChildAdded:Connect(function(button) -- When A Template Adds into the List
   if button:IsA("TextButton") then -- Ignores UILayouts/Other Items Except Buttons
       button.Activated:Connect(function()
          if debounce == false then -- Check if Variable is False
             debounce = true -- Set Variable To True To Prevent Clicking Buttons
             onKick(button) -- Call the Kick Function
             button:Destroy() -- Destroy Button, Player will be Kicked (This also Helps if your PlayerList Updater Errors)
             wait(0.15) 
             debounce = false -- Enable Clicking Buttons 
          end
       end)
    end
end)

Now for the ServerScriptService (Server) Part,

local Remote = game.ReplicatedStorage.RemoteEvent -- Define the Remote Event Inside Replicated Storage

Remote.OnServerEvent:Connect(function(Player,Str) -- Player is the First Parameter, and The Second is  the String/PlayerName to Kick
    pcall(function() -- Wrap in Pcall to Prevent Errors
        local plr = game:GetService("Players")[Str] or nil
        if plr ~= nil then -- Player Exists
           plr:Kick() -- This Kicks the Player from the Game Server
        end
    end)
end)

Now you Want the Frame to Automatically Add Players onto The List.
In the Scrolling Frame, Add A LocalScript (Call it PlayerAdder [Not Neccessary])

Now Add A UIListLayout inside the ScrollingFrame and Customize it According to Your Perspective.
This ListLayout will Automatically Sort the PlayerButtons.

Add A TextButton Inside the ScrollingFrame you Have and Rename it to Template.
Customize It Accordingly, And Parent it to the localScript we will Be Scripting Now.

local Scroll = script.Parent -- This LocalScript is Inside the Scrolling Frame which Consists of Buttons
local PlayersService = game:GetService("Players") -- Players Service

function update() -- Make  A Function
   for i,child in pairs(Scroll:GetChildren()) do -- Get All Existing Buttons
      if child:IsA('TextButton') then child:Destroy() end -- Destroy Them
   end

   for i,plr in pairs(PlayersService:GetChildren()) do -- Loop Through Players
      if plr ~= PlayersService.LocalPlayer then -- Its not the Same Player (the one who has the gui)
        local TextButton = script:FindFirstChild("Template"):Clone() -- This is A Template Text Button inside the Script, You need to Customize A Text Button and Add it In here
        TextButton.Name = plr.Name .. "'s Button" -- Set the name of Cloned
        TextButton.Text = plr.Name -- Set the Text to Players Name
        TextButton.Parent = Scroll -- Set the Parent to the Scrolling List
     end
   end
end

update() -- Call Function for First Time

PlayersService.PlayerAdded:Connect(function()
    update() -- When A Player Joins, Update List
end)

PlayersService.PlayerRemoving:Connect(function()
    update() -- When A Player Leaves, Update List
end)
1 Like

I’m gonna try that out right now, but how would it set the buttons to the players name?

like the Text buttons Text would be the name of the player like One button would be Player1 and anohther to be player 2

If you would really like to use a UI for it, then the best thing is using a Remote Event as @Kaid3n22 and @WheezWasTaken have suggested.

The harder way out if using admin commands by installing an admin system on your game, where as you can use a chat message to kick a player out of the game.