Kick cmd errors

local kick_module = {}
local Players_1 = game:GetService(“Players”)
local PermsClone = require(game.ServerScriptService.CommandsMain.Config)

local function PartialName(PartialName)
local Players = Players_1:GetPlayers()
local FoundPlayer = nil

for i = 1, #Players do 
	local CurrentPlayer = Players[i]

	if string.find(string.lower(CurrentPlayer.Name), string.lower(PartialName)) then
		FoundPlayer = CurrentPlayer.Name

		if not FoundPlayer then
			FoundPlayer = CurrentPlayer
		end
	else
		return FoundPlayer

	end
end

end

local prefix = “:” – The Prefix ex :,!,/
local command_1 = “kick” – The command
local kickreason = "You have been kicked from the server by: " – Dont remove the space

kick_module.kickcmd = function ()
Players_1.PlayerAdded:Connect(function(PlayerWhoJoined)
PlayerWhoJoined.Chatted:Connect(function(Msg_Unlowered)
print(“Command Fired”)
local Msg_Lowered = Msg_Unlowered:lower(string)
local Args = Msg_Lowered:split(" ")
if Args[1] == prefix…command_1 then

			print(prefix..command_1)
			if PlayerWhoJoined:GetRankInGroup(PermsClone.GroupID) >= PermsClone.MinAdminRank then
				print("Player is min rank.")
				local NameOfPlayerToKick = Args[2]
				local PlayerToKick = game.Players:FindFirstChild(PartialName(NameOfPlayerToKick))

				if PlayerToKick == PlayerWhoJoined then
					print(PlayerToKick)
					game:GetService("ReplicatedStorage").CommandRemotes.NotifyClients:FireClient(PlayerToKick,"Uh oh...","You can't kick yourself!")
					return nil
				elseif PlayerToKick.Name ~= PlayerWhoJoined.Name then	
					PlayerToKick:Kick(kickreason..PlayerWhoJoined)
				end
			end
		end
	end)
end)

end

return kick_module
Hello, my kick command errors with Argument Missing or nil on line 44

I’m trying to find where line 44 is, and this seems to be it:

Is there a Reason these Conditions are different? Couldn’t you just use else?

1 Like
			local PlayerToKick = game.Players:FindFirstChild(PartialName(NameOfPlayerToKick))

this was the line of code that got an error

PLEASE, put your code in a code block.

1 Like

I believe this is because you are returning the player object, not name.

1 Like

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