Lava Script Error

I have an Obstacle Course game on top of lava, and when I play the game, I get an error from the script that will kill the player if that player touches the lava, here is the script:

function onTouched(part)
 local h = part.Parent:FindFirstChild("Humanoid")
 if h~=nil then
  h.Health = h.Health-100
 end
end
script.Parent.Touched:connect(onTouched)

The error says this:
12:01:24.949 - Workspace.Lava.Script:2: attempt to index nil with ‘FindFirstChild’
How do I fix this? Thank you very much

In the function, 1 of the parameters should be hit

you would have to do, hit.Parent:FindFirstChild(“Humanoid”)

So it would be:

function onTouched(part)
 local h = hit.Parent:FindFirstChild("Humanoid")
 if h~=nil then
  h.Health = h.Health-100
 end
end
script.Parent.Touched:connect(onTouched)

???

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        humanoid.Health = humanoid.Health - 100
    end
end)

or

local function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        humanoid.Health = humanoid.Health - 100
    end
end

script.Parent.Touched:Connect(onTouched)

No no here:

function onTouched(hit)
 local h = hit.Parent:FindFirstChild("Humanoid")
 if h~=nil then
  h.Health = h.Health-100
 end
end
script.Parent.Touched:connect(onTouched)

Ima try that and report back to see if it works, thank you

I got this error @dmksa123

12:08:46.096 - Workspace.Lava.Script:2: Unexpected Unicode character: U+201c. Did you mean '"'?

Uhhhhh, how??? Can I see what you wrote?

function onTouched(hit)
local h = hit.Parent:FindFirstChild(“Humanoid”)
if h~=nil then
h.Health = h.Health-100
end
end
script.Parent.Touched:connect(onTouched)

It’s because the quotations are weird. Just replace them with the ones on your keyboard. " "

I thought so… Ima try that now

Yeah do what @DarkDanny04 said.

Alright, I got no errors, thank you guys very much

You should use h.Health = 0 instead of h.Health = h.Health - 100

If you use h.Health = h.Health - 100, weird things could happen like the health bar constantly going into the negatives as the player is falling apart.