How could i do a proper kick command?

so how could i make a kick cmd with a reason

i already started on this but theres one problem
my “reason” will only take the third argument so if theres a space in the reason it wont work

--Admin Script
	plr.Chatted:Connect(function(msg)
				local loweredString = string.lower(msg)
				local args = string.split(loweredString," ")
				
		
				
			if args[1] == prefix..'kick' then
				adminmodule.Kick(args[2], args[3])
			end
	
		
			end) 
--Module
function admin.Kick(player, reason)
	for i,players in pairs(game.Players:GetPlayers()) do
		if string.sub(string.lower(players.Name), 1, string.len(player)) == string.lower(player) then

players:Kick(reason)
		else
			print('player not found')
		end
	end
	
end

Combine all of the words in args back into a string then send it as the second parameter

local count = 4
local reason = args[3]
while count <= #args do
    reason = reason.." "..args[count]
    count = count + 1
end

is there a specific reason on why count is 4?

Because your reason starts from the 3rd item in the table and I don’t wanna put a space before the start of the reason

Just note that both our scripts will result in an index out of bounds error if no reason is given so if that might happen consider a failsafe

table.concat:

local args = string.split(loweredString, " ")

if args[1] == prefix..'kick' then
    adminmodule.Kick(args[2], table.concat(args, " ", 3)) -- args being the array, " " being the separator (whitespace), and 3 being the starting index of the array (args[3])
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.