-
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'
-
What is the issue? Include screenshots / videos if possible!
The issue is that I do not know how to fix the error. -
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