Needing somes help

  1. What do you want to achieve? Keep it simple and clear!
    A kick command.

  2. What is the issue? Include screenshots / videos if possible!
    I do not know how to make a part of the code, and would like feedbacks.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using tutorials but none used Reason: hi with example.

You would have to listen to player.Chatted, and do some string formatting that would look like:

if (string.sub(message, 1, 5) == ":kick") then
    local playerToKick = (game:GetService("Players"):FindFirstChild(string.split(message, " ")[2]))
    if (playerToKick) then 
       playerToKick:Kick(string.format("You have been kicked by %s", player.Name)) -- // player is the player that you are listening to.
    end
end

There may be some writing mistakes as I wrote it all on mobile.

1 Like
local permissions = {
	1961531600 -- you
}

local players = game:GetService("Players")

local function getTokens(str)
	local result = {}
	for word in str:gmatch("%S+") do
		table.insert(result, word)
	end
	return result
end

local function findPlayer(name)
	if (name == nil) then return end
	for _, player in ipairs(players:GetPlayers()) do
		if (player.Name:lower():sub(1, #name) == name:lower()) then
			return player
		end
	end
end

players.PlayerAdded:Connect(function(player)
	if (table.find(permissions, player.UserId)) then
		player.Chatted:Connect(function(msg)
			local tokens = getTokens(msg:lower())
			if (tokens[1] == "!kick") then
				local other = findPlayer(tokens[2])
				if (other) then
					other:Kick("You've been kicked by "..player.Name)
				end
			end
		end)
	end
end)
2 Likes