Hey, so i have a sword script and at the line where it says "if humanoid.Parent ~= tool.Parent and debounce == true and humanoid.Health > 0 and tool.Parent ~= player.backpack then it gives an error saying “attempt to index nil with Parent” and it spams the output with these errors, which is very annoying. and the script works fine as well. can someone help me fix this issue?
here is the code below (yes its long)
tool.Hitbox.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local hum = tool.Parent.Humanoid
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
local eplayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if humanoid.Parent ~= tool.Parent and debounce == true and humanoid.Health > 0 and tool.Parent ~= player.Backpack then
humanoid.Health -= 8.5
debounce = false
local tagval = hit.Parent:FindFirstChildWhichIsA("IntValue")
tagval.Name = player.Name
lbremote:FireClient(player)
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if MS:UserOwnsGamePassAsync(player.UserId,x2) then
player.leaderstats.Swings.Value = player.leaderstats.Swings.Value + 2
else
player.leaderstats.Swings.Value = player.leaderstats.Swings.Value + 1
end
local clonekillscript = game.ServerStorage.DebuffScripts.KillLB:Clone()
if hit.Parent:FindFirstChild("KillLB") == nil then
if humanoid.Health > 0 then
clonekillscript.Parent = humanoid.Parent
end
else
if humanoid.Health > 0 then
hit.Parent.KillLB:Destroy()
clonekillscript.Parent = humanoid.Parent
end
end
end
end)