Cant define player to kick in kick script

local Prefix = "/"
local Admins = {115733309,}
-- Commands
local Balance = require(game.ServerScriptService.Commands.Balance)
local Coinflip = require(game.ServerScriptService.Commands.Coinflip)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local loweredMessage = string.lower(message)
		local args = string.split(loweredMessage," ")

		if args[1] == Prefix.."bal" then 
				Balance.BalanceFunction(player)
		end
	end)
end)

--Admin Commands
local Kick = require(game.ServerScriptService.Commands.Kick)

game.Players.PlayerAdded:Connect(function(player)
	for i,v in pairs(Admins) do
		if player.UserId == v then
	player.Chatted:Connect(function(message)
		local loweredMessage = string.lower(message)
		local args = string.split(loweredMessage," ")
		
		if args[1] == Prefix.."kick" then
			local playertokick = string.sub(message,6)
			Kick.KickFunction(playertokick)
				end
			end)
		end
	end
end)
local Commands = {}
	Commands.KickFunction = function(player)
		player:Kick()
	end
return Commands

ServerScriptService.Commands.Kick:3: attempt to call a nil value

so its like 1 am and im to lazy to define the player so yk yk ima head off

1 Like

In your ModuleScript, you created a function incorrectly. The ModuleScript should look something like this.

local Commands = {}

function Commands.KickFunction(player)
	player:Kick()
end

return Commands

Maybe look at this as well: https://education.roblox.com/en-us/resources/intro-to-module-scripts

I’m pretty sure you can also do it the way the OP did it

Also you have to pass the player object, not the name of the player @Roastdbacon

game.Players.PlayerAdded:Connect(function(player)
	for i,v in pairs(Admins) do
		if player.UserId == v then
	player.Chatted:Connect(function(message)
		local args = string.split(message," ")

		if args[1] == Prefix.."kick" then 
			local playertokick = game.Players:FindFirstChild(args[2])
			local message = args[3]
			Kick.KickFunction(playertokick,message)
				end
			end)
		end
	end
end)