Need help with a lightsaber script again

  1. What do you want to achieve? Keep it simple and clear!
    A lightsaber that does not error when recognizing the target.
  2. What is the issue? Include screenshots / videos if possible!
    “Attempted to index nil with Health”
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None worked.
Tool.contact.Touched:Connect(function(touch)

if Equipped and debounce == false then

if touch.Parent:FindFirstChildWhichIsA("Humanoid") and touch:FindFirstAncestorWhichIsA("Player") ~= playeruser then

debounce = true

touch.Parent:FindFirstChild("Humanoid").Health -= (20)

LightSaberHitSounds[math.random(1,4)]:Play()

wait(1)

debounce = false

elseif touch.Parent.Parent:FindFirstChildWhichIsA("Humanoid") then

debounce = true

touch.Parent:FindFirstChild("Humanoid").Health -= (20)

LightSaberHitSounds[math.random(1,4)]:Play()

wait(1)

debounce = false

end

end

end)

I don’t understand why it formatted my code so weirdly, please know I don’t make my scripts like this. :joy:

Which line is the error on?(extra word count)

1 Like

Line 34 I believe is where the error is located.

Hello,

I think I found the issue but I’m quite not sure if it is though.

On line 3, there are 2 equals so I’m guessing that’s the solution but I don’t know.

I’m not really a scripter I’m just trying to help.

-TheDevDoge

1 Like

That just means equal to like is debounce equal to true(or false in this case)

If it’s indexing nil with health then that means it’s not finding a Humanoid try saying touch.parent.parent:FindFirstChild(’Humanoid’)

1 Like

Thank you, I forgot to change it to that.

1 Like