Argument 1 missing or nil

Solved! Thanks for the help everyone.

Where exactly does it say, the argument1 missing or nil?
Secondly, I suggest scripting it like this.

local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"

game.Players.PlayerAdded:Connect(function(plr)
	for i, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" then
					if msg[2] then
						local target = game:GetService("Players"):FindFirstChild(msg[2].Name)
						perms:PlayerKick(target,"failed.")
					end
				end
			end)
		end
	end
end)
1 Like

It’s said it at 'perms:PlayerKick(target,“failed”.).

Sorry for the late response!

1 Like

Alright, let me see.
Could I request the playermoudle, and what’s in it? As that could be the issue.

Try this, remove the “.” in “failed” as that could error the script.

	perms:PlayerKick(target,"failed")
1 Like

Nope, it’s still not working, and the error is the same.

Could I request the kick Module, and what’s in it? As that could be the issue, and could I get a picture of the error too, sorry for the amount of requests haha.

Yes, of course! Give me one second.

1 Like

Hi! Try with this, it worked fine for me.

local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"

game.Players.PlayerAdded:Connect(function(plr)
	for _, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" and msg[2] then
					local target = game:GetService("Players"):FindFirstChild(msg[2])
					perms:PlayerKick(target, "failed.")
				end
			end)
		end
	end
end)

Trying to get the .Name of a string (message) cause an error.

Edit: Replied wrong person.

1 Like

Kick module that you made:

Output:

1 Like

Argument 1, or nil missing
Meaning that you will require a reason for it, a work-around for it would be this.

local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"
local Reason = "hi lol fattie u failed"

game.Players.PlayerAdded:Connect(function(plr)
	for _, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" and msg[2] then
					local target = game:GetService("Players"):FindFirstChild(msg[2])
					perms:PlayerKick(target, Reason)
				end
			end)
		end
	end
end)

If that doesn’t work it means the target that you are getting is nil. (Meaning no value)

Didn’t work… This is confusing.

local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"
local Reason = "hi lol fattie u failed"


game.Players.PlayerAdded:Connect(function(plr)
	for _, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" and msg[2] then
					local target = game.Players:FindFirstChild(msg[2])
					perms:PlayerKick(target, Reason)
				end
			end)
		end
	end
end)

This should work.

Attempt to call a nil value???

1 Like

May you send the current code that you have putted?

Oh wait. It’s because there is not ‘.Name’ probably. Let me check if that the case.

No justly, don’t put it. Attemping to get the .Name of a String will cause an error.

1 Like
local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"
local Reason = "failed cuz ur fat"

game.Players.PlayerAdded:Connect(function(plr)
	for _, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" and msg[2] then
					local target = game:GetService("Players"):FindFirstChild(msg[2])
					perms:PlayerKick(target, Reason or "failed")
				end
			end)
		end
	end
end)

Try this:

--// Script
local SS = game:GetService("ServerScriptService")
local perms = require(SS:WaitForChild("MainModule"))
local authorized = {"achdef"}
local prefix = "!"
local Reason = "Failed."

game.Players.PlayerAdded:Connect(function(plr)
	for _, authorized in pairs(authorized) do
		if plr.Name == authorized then
			plr.Chatted:Connect(function(message)
				local msg = message:split(" ")
				if msg[1] == prefix.."fail" and msg[2] then
					perms:PlayerKick(msg[2], Reason)
				end
			end)
		end
	end
end)

--// ModuleScript
function banService:PlayerKick(target, reason)
	-- Check if player exists in 'Players' and if there's a reason
	local player = game:GetService("Players"):FindFirstChild(target)
	if player and reason then
		player:kick(reason)
		print("Successfully kicked", player.Name)
	end
end

FindFirstChild returns false if the instance is not existing, so if you put a bad name it could send as arguments: perms:PlayerKick(false, Reason)

1 Like

Okay, I fixed it. Thanks for the help y’all!

1 Like

I see this thread has already been solved, but I was writing this so I’ll still leave it here. I debugged your problem just out of curiosity instead of just rewriting the whole thing.

By default this module writes this call as KickPlayer, not PlayerKick (maybe you changed it, in which case this isn’t a problem).

Additionally, that call will never work by default within the module because it tries to index nonexistant variables. This is not your fault.

2 Likes