Argument 1 missing or nil

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix the error that I kept getting.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that I can’t fix it. I do not know how.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I searched the fix of the error but I couldn’t find anything similar to my exact problem.

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPack = game:GetService("StarterPack")

-- Variables
local player, character, humanoid, tool
tool = script.Parent.Parent
character = tool.Parent.Parent.Character
humanoidVar = character:WaitForChild("Humanoid")
player = Players:GetPlayerFromCharacter(character)

-- ASCS Folder
local ASCS = ReplicatedStorage.ASCS

-- Remote Events Folder
local RemoteEventsFolder = ASCS.RemoteEvents

-- Assets Folder
local AssetsFolder = ASCS.Assets

-- OtherFolders
local NPCFolder = workspace.NPCs

-- Values Folder
local GlobalValuesFolder = ASCS.Values
local ToolValuesFolder = tool.Values

-- Remote Events
local RemoteEvents = {
	RemoteEventsFolder.AddCombo;
	RemoteEventsFolder.ResetCombo;
	RemoteEventsFolder.HitStop;
	RemoteEventsFolder.HitStart;
}

-- Values
local Values = {
    ToolValuesFolder:WaitForChild("CanDamage");
    GlobalValuesFolder:WaitForChild("ArmorAmount");
    ToolValuesFolder:WaitForChild("Combo");
    GlobalValuesFolder:WaitForChild("ArmorEnabled");
}

-- Tool Config Folder
local WeaponConfig = ASCS.ToolConfig

-- Tool
local tool = script.Parent.Parent

-- Modules
local RaycastHitboxV4 = require(ASCS.Modules.RaycastHitboxV4)
local GlobalConfig = require(ASCS.GlobalConfig.Config)
local Config = require(WeaponConfig:FindFirstChild(tool.Name))


print("Character, humanoid, tool and player is set in the variable.")

local Model = ASCS.Models:FindFirstChild(tool.Name).Handle:Clone()
Model.Parent = tool

-- Hitbox
local newHitbox = RaycastHitboxV4.new(tool:WaitForChild("Handle"))
newHitbox.RaycastParams = RaycastParams.new()
newHitbox.RaycastParams.FilterDescendantsInstances = {character}
newHitbox.RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist

newHitbox.OnHit:Connect(function(hit, humanoid)
    print(hit)
    if Config.CanHitNpc and not Config.CanHitPlayer then
        if NPCFolder:FindFirstChild(humanoid.Parent.Name) and humanoid.Parent ~= Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent)) then
                if Config.CanBreakArmor then
                    if humanoid.ArmorAmount.Value > 0 then
                        humanoid.ArmorAmount.Value -= Config.NormalDamage
                    elseif humanoid.ArmorAmount.Value == 0 then
                        humanoid:TakeDamage(Config.NormalDamage)
                    end
                elseif not Config.CanBreakArmor then
                    humanoid:TakeDamage(Config.NormalDamage)
                end
            end
    elseif Config.CanHitPlayer and not Config.CanHitNpc then
        if humanoid.Parent == Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent)) then
            if Config.CanBreakArmor then
                if humanoid.ArmorAmount.Value > 0 then
                    humanoid.ArmorAmount.Value -= Config.NormalDamage
                elseif humanoid.ArmorAmount.Value == 0 then
                    humanoid:TakeDamage(Config.NormalDamage)
                end
            elseif not Config.CanBreakArmor then
                humanoid:TakeDamage(Config.NormalDamage)
            end
        else
            return
        end
    elseif not Config.CanHitPlayer and not Config.CanHitNpc then
        return
    elseif Config.CanHitPlayer and Config.CanHitNpc then
        if NPCFolder:FindFirstChild(humanoid.Parent.Name) then
            humanoid:TakeDamage(Config.NormalDamage)
        end
    end
end)


RemoteEvents[4].OnServerEvent:Connect(function()
	newHitbox:HitStart()
end)

RemoteEvents[3].OnServerEvent:Connect(function()
	newHitbox:HitStop()
end)

RemoteEvents[1].OnServerEvent:Connect(function()
    Values[3].Value += 1
end)

RemoteEvents[2].OnServerEvent:Connect(function()
    Values[3].Value = 0
end)

Error: Argument 1 missing or nil - Server - Server:71

Line 71: if NPCFolder:FindFirstChild(humanoid.Parent.Name) and humanoid.Parent ~= Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent)) then

this may be erroring when GetPlayerFromCharacter returns nil, because then you’re doing FindFirstChild(nil)

a few more issues on that line, that would be the player, so you wouldnt use FindFirstChild with that
and humanoid.Parent can’t be a player, it would be the player’s character instead

assuming humanoid.Parent isnt in NPCFolder, I would handle the if statement like:

local matchingPlayer = Players:GetPlayerFromCharacter(humanoid.Parent)
local matchingNPC = NPCFolder:FindFirstChild(humanoid.Parent.Name)
if (
   matchingNPC
   and (
      (matchingPlayer == nil)
      or (humanoid.Parent ~= matchingPlayer.Character)
   )
) then

Yeah, but I am hitting a dummy that is located in the NPCs folder. So It shouldn’t return nil.

yes, that would return nil in GetPlayerFromCharacter

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPack = game:GetService("StarterPack")

-- Variables
local player, character, humanoid, tool
tool = script.Parent.Parent
character = tool.Parent.Parent.Character
humanoidVar = character:WaitForChild("Humanoid")
player = Players:GetPlayerFromCharacter(character)

-- ASCS Folder
local ASCS = ReplicatedStorage.ASCS

-- Remote Events Folder
local RemoteEventsFolder = ASCS.RemoteEvents

-- Assets Folder
local AssetsFolder = ASCS.Assets

-- OtherFolders
local NPCFolder = workspace.NPCs

-- Values Folder
local GlobalValuesFolder = ASCS.Values
local ToolValuesFolder = tool.Values

-- Remote Events
local RemoteEvents = {
	RemoteEventsFolder.AddCombo;
	RemoteEventsFolder.ResetCombo;
	RemoteEventsFolder.HitStop;
	RemoteEventsFolder.HitStart;
}

-- Values
local Values = {
    ToolValuesFolder:WaitForChild("CanDamage");
    GlobalValuesFolder:WaitForChild("ArmorAmount");
    ToolValuesFolder:WaitForChild("Combo");
    GlobalValuesFolder:WaitForChild("ArmorEnabled");
}

-- Tool Config Folder
local WeaponConfig = ASCS.ToolConfig

-- Tool
local tool = script.Parent.Parent

-- Modules
local RaycastHitboxV4 = require(ASCS.Modules.RaycastHitboxV4)
local GlobalConfig = require(ASCS.GlobalConfig.Config)
local Config = require(WeaponConfig:FindFirstChild(tool.Name))


print("Character, humanoid, tool and player is set in the variable.")

local Model = ASCS.Models:FindFirstChild(tool.Name).Handle:Clone()
Model.Parent = tool

-- Hitbox
local newHitbox = RaycastHitboxV4.new(tool:WaitForChild("Handle"))
newHitbox.RaycastParams = RaycastParams.new()
newHitbox.RaycastParams.FilterDescendantsInstances = {character}
newHitbox.RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist

newHitbox.OnHit:Connect(function(hit, humanoid)
    print(hit)
    if Config.CanHitNpc and not Config.CanHitPlayer then
        if NPCFolder:FindFirstChild(humanoid.Parent.Name) and humanoid.Parent ~= Players:GetPlayerFromCharacter(humanoid.Parent) then
                if Config.CanBreakArmor then
                    if humanoid.ArmorAmount.Value > 0 then
                        humanoid.ArmorAmount.Value -= Config.NormalDamage
                    elseif humanoid.ArmorAmount.Value == 0 then
                        humanoid:TakeDamage(Config.NormalDamage)
                    end
                elseif not Config.CanBreakArmor then
                    humanoid:TakeDamage(Config.NormalDamage)
                end
            end
    elseif Config.CanHitPlayer and not Config.CanHitNpc then
        if humanoid.Parent == Players:GetPlayerFromCharacter(humanoid.Parent) then
            if Config.CanBreakArmor then
                if humanoid.ArmorAmount.Value > 0 then
                    humanoid.ArmorAmount.Value -= Config.NormalDamage
                elseif humanoid.ArmorAmount.Value == 0 then
                    humanoid:TakeDamage(Config.NormalDamage)
                end
            elseif not Config.CanBreakArmor then
                humanoid:TakeDamage(Config.NormalDamage)
            end
        else
            return
        end
    elseif not Config.CanHitPlayer and not Config.CanHitNpc then
        return
    elseif Config.CanHitPlayer and Config.CanHitNpc then
        if NPCFolder:FindFirstChild(humanoid.Parent.Name) then
            humanoid:TakeDamage(Config.NormalDamage)
        end
    end
end)


RemoteEvents[4].OnServerEvent:Connect(function()
	newHitbox:HitStart()
end)

RemoteEvents[3].OnServerEvent:Connect(function()
	newHitbox:HitStop()
end)

RemoteEvents[1].OnServerEvent:Connect(function()
    Values[3].Value += 1
end)

RemoteEvents[2].OnServerEvent:Connect(function()
    Values[3].Value = 0
end)

I fixed it! I must’ve done only Players:GetPlayerFromCharacter(humanoid.Parent)