Attempt to index nil with 'Character'

  1. What do you want to achieve? Keep it simple and clear!
    I’ve been making a sword combat system but I get the error on the title.
Players.SilentDevReal.Backpack.Greatsword.Scripts.Server:68: attempt to index nil with 'Character'
  1. What is the issue? Include screenshots / videos if possible!
    The issue is that I do not know how to fix the error.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’m not sure if there is a solution for my current problem since it’s a sword combat system.

-- 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

-- 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 humanoid.Parent ~= Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent).Character) 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
            end
        else
            return
        end
    elseif not Config.CanHitNpc and Config.CanHitPlayer then
        if humanoid.Parent == Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent).Character) 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
            end
        else
            return
        end
    elseif not Config.CanHitNpc and not Config.CanHitPlayer then
        return
    elseif Config.CanHitNpc and Config.CanHitPlayer 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
            end
        else
            return
	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)

Line 68 → lua if humanoid.Parent ~= Players:FindFirstChild(Players:GetPlayerFromCharacter(humanoid.Parent).Character) then

Is the line that says character = script.Parent.Parent referring to the character model?

Try removing the Character at the end of character = tool.Parent.Parent.Character and leave it as character = tool.Parent

I don’t think .Character is an existing object in your game. I am just presuming that to be the case.

If the tool is inside your character model you only would need to write tool.Parent

tool.Parent.Parent would be fine assuming the tools are in StarterPack.

I’ve set it to script.Parent.Parent.Character because I needed to get the character even if the player wasn’t equipping the tool. But I’m a bit confused because: what if I put it in startergui (for example)? Simply it wouldn’t work. So I need something that would help me to find the character of the player.
@gutpack @PluggedByJohn