Argument 1 missing or nil

Never seen this error before, also can’t find any other threads that seem to help.

This is just a kill leaderstats script.

The error:

The script:

local Settings = require(script.Parent.Settings)
script.Parent = game.ServerScriptService
stands = {}
CTF_mode = false

function onHumanoidDied(humanoid, player)
	local stats = player:findFirstChild("leaderstats")
	if stats ~= nil then
		local deaths = stats:findFirstChild(Settings.LeaderboardSettings.DeathsName)
		if deaths then
			deaths.Value = deaths.Value + 1
		end
		
		if Settings.LeaderboardSettings.KOs then
			local killer = getKillerOfHumanoidIfStillInGame(humanoid)
			handleKillCount(humanoid, player)
		end
	end
end

function onPlayerRespawn(property, player)

	if property == "Character" and player.Character ~= nil then
		local humanoid = player.Character.Humanoid
		local p = player
		local h = humanoid
		if Settings.LeaderboardSettings.WOs then
			humanoid.Died:connect(function() onHumanoidDied(h, p) end )
		end
	end
end

function getKillerOfHumanoidIfStillInGame(humanoid)

	local tag = humanoid:findFirstChild("creator")

	if tag ~= nil then

		local killer = tag.Value
		if killer.Parent ~= nil then
			return killer
		end
	end

	return nil
end

function handleKillCount(humanoid, player)
	local killer = getKillerOfHumanoidIfStillInGame(humanoid)
	if killer ~= nil then
		local stats = killer:findFirstChild("leaderstats")
		if stats ~= nil then
			local kills = stats:findFirstChild(Settings.LeaderboardSettings.KillsNames)
			if kills then
				if killer ~= player then
					kills.Value = kills.Value + 1	
				else
					kills.Value = kills.Value - 1
				end
			else
				return
			end
		end
	end
end

Any help is greatly appreciated, thanks!

It seems humanoid is nil in

if Settings.LeaderboardSettings.KOs then
	local killer = getKillerOfHumanoidIfStillInGame(humanoid)
	handleKillCount(humanoid, player) -- This line here
end

Can you try printing the humanoid before calling handleKillCount()? This is just to make sure if it is nil or not.

1 Like

Printing “function 0xaee64e99c350540a”, so seems to be fine up to that point?

Edit: Also still just trying to figure out just what this error means in general.

That means humanoid is a function, when you are calling this, make sure you pass a humanoid, and not a function or anything else.

1 Like

I think you need to change the order of your functions.
Try changing the script to this:

local Settings = require(script.Parent.Settings)
script.Parent = game.ServerScriptService
stands = {}
CTF_mode = false

local function handleKillCount(humanoid, player)
	local killer = getKillerOfHumanoidIfStillInGame(humanoid)
	if killer ~= nil then
		local stats = killer:findFirstChild("leaderstats")
		if stats ~= nil then
			local kills = stats:findFirstChild(Settings.LeaderboardSettings.KillsNames)
			if kills then
				if killer ~= player then
					kills.Value = kills.Value + 1	
				else
					kills.Value = kills.Value - 1
				end
			else
				return
			end
		end
	end
end

local function onHumanoidDied(humanoid, player)
	local stats = player:findFirstChild("leaderstats")
	if stats ~= nil then
		local deaths = stats:findFirstChild(Settings.LeaderboardSettings.DeathsName)
		if deaths then
			deaths.Value = deaths.Value + 1
		end
		
		if Settings.LeaderboardSettings.KOs then
			local killer = getKillerOfHumanoidIfStillInGame(humanoid)
			handleKillCount(humanoid, player)
		end
	end
end

local function onPlayerRespawn(property, player)

	if property == "Character" and player.Character ~= nil then
		local humanoid = player.Character.Humanoid
		local p = player
		local h = humanoid
		if Settings.LeaderboardSettings.WOs then
			humanoid.Died:connect(function() 
				print("This is a test message. Humanoid Name:  "..humanoid.Parent.Name.." Player Name: "..player.Name)
				onHumanoidDied(humanoid, player) 
			end)
		end
	end
end

local function getKillerOfHumanoidIfStillInGame(humanoid)

	local tag = humanoid:findFirstChild("creator")

	if tag ~= nil then

		local killer = tag.Value
		if killer.Parent ~= nil then
			return killer
		end
	end

	return nil
end

You need to have function handleKillCount before onHumanoidDied.
I added some prints so after you changed the script to this show me your output.

2 Likes