Admin Panel Kick Script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Trying to make a kick command for my admin panel.
  2. What is the issue? Include screenshots / videos if possible!
    It won’t kick the player, and their no error’s in the output.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Couldn’t find any solutions, tried websites and etc.

Some of my code:

			elseif Command:sub(1, 6) == CommandPrefix.."Kick " or Command.sub(1, 6) == CommandPrefix.."kick " then
				local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
				TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

you’re adding an extra space to the “Kick”

also your sub are different Command:sub(1,6) Command.sub(1,6)

Oops, let try it out now. Also question how can I make make a moderator put a reason??

What do you mean my sub’s are different?

Oop, I see the error. Let me change it

It ain’t working.

				--Kick Command
			elseif Command:sub(1, 6) == CommandPrefix.."Kick" or Command:sub(1, 6) == CommandPrefix.."kick" then
				local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
				TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
				--Kick Command

I typed this in the chat. “:kick DeveloperCoolBoi”

here’s a better way to do it

local YourPrefix = "!"
local SplittedCommand = string.split(Command," ")
if SplittedCommand[1] and SplittedCommand[2] then
local Player = game.Players:FindFirstChild(SplittedCommand[2]) 
local Reason = SplittedCommand[3]
if SplittedCommand[1]:lower() == YourPrefix.."kick" and Player then
if Reason then
Player:Kick("You have been kicked for : "..Reason)
else
Player:Kick("You Have Been Kicked.")
end
end
end
1 Like
local Players = game.Players
local CommandPrefix = ":"
local Admins = {
	["DeveloperCoolBoi"] = "Admin"
	
}


Players.PlayerAdded:Connect(function(Admin)
	if Admins[Admin.Name] then
		Admin.Chatted:Connect(function(Command)
	--Kick Command
			elseif Command:sub(1, 6) == CommandPrefix.."Kick" or Command:sub(1, 6) == CommandPrefix.."kick" then
				local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
				TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
				--Kick Command

Here’s how my script looks like (most of it)

I’m just looking how to make it kick a player. I don’t think I need a mod to add a reason.

i suggest you to use this code instead, with the reason or without, lemme know if you want to remove the Reason

local CommandPrefix = ":"
local Admins = {
	["DeveloperCoolBoi"] = "Admin"
	
}


Players.PlayerAdded:Connect(function(Admin)
		Admin.Chatted:Connect(function(Command)
                       	if Admins[Admin.Name] then

                         local SplittedCommand = string.split(Command," ")

                        if SplittedCommand[1] and SplittedCommand[2] then

                   local Player = game.Players:FindFirstChild(SplittedCommand[2])

                 local Reason = SplittedCommand[3]

                if SplittedCommand[1]:lower() == CommandPrefix.."kick" and Player then

             if Reason then
               Player:Kick("You have been kicked for : "..Reason)
               else
                Player:Kick("You Have Been Kicked.")
end
end
end
			end
end)
end)

I don’t understand your code… That’s why I want to use the one I wrote. Do u have any suggestions for my code, on how to at least make it kick a player?

1 Like

Here you go, I usedstring:lower(), string:gsub() & string:find() to fix it.

Players.PlayerAdded:Connect(function(Admin)
	if Admins[Admin.Name] then
		Admin.Chatted:Connect(function(Command)
            --Kick Command?
			elseif Command:lower():find(CommandPrefix.."kick") then
				local playerUsername = Command:gsub(CommandPrefix.."kick ","")
				local TargetedPlayer = Players:FindFirstChild(playerUsername)
				if TargetedPlayer then
					TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
				end

Args are so much easier (char limit)

What does all of that code mean what u added to it??

string:lower() can turn “SOMERANDOMSTRING” into “somerandomstring”.
string:find() looks for the first match of pattern in the string (":kick")
string:gsub() removes the ":kick " part of the command allowing to fetch the username.

here i can explain the code to you

local CommandPrefix = ":"
local Admins = {
	["DeveloperCoolBoi"] = "Admin"
	
}


Players.PlayerAdded:Connect(function(Admin)
		Admin.Chatted:Connect(function(Command)
                       	if Admins[Admin.Name] then -- Checks if the Player is in the AdminsTable

                         local SplittedCommand = string.split(Command," ") -- Splits the message into spaces

                        if SplittedCommand[1] and SplittedCommand[2] then -- Checks if there is the kick command & the player in the message

                   local Player = game.Players:FindFirstChild(SplittedCommand[2]) -- Finds the player in PlayersService

                 local Reason = SplittedCommand[3]

                if SplittedCommand[1]:lower() == CommandPrefix.."kick" and Player then -- lowercasing /kick and checking if the message contains the PlayerName in it

             if Reason then -- Checks if there is a Reason
               Player:Kick("You have been kicked for : "..Reason)
               else
                Player:Kick("You Have Been Kicked.")
end
end
end
			end
end)
end)

Your script is setting up unneeded connections.
It should check if the player is in the adminTable before setting up the Admin.Chatted:Connect() connection.

nope, actually lets say if an admin can insert admins in game, checking if the player is an admin before the chatted event won’t make that work.

along with that, your script doesn’t work.

  1. in line 5 elseif needs to be changed to if

  2. your script is missing some ends