Help with an Error: attempt to index nil with 'Parent'

HI, am trying to make a script that clones a script into a player that has touched a hitbox. Here is the script:

local u = false 
script.Parent.Touched:connect(function(part)
	if not u then
		u = true
		if part.Parent then
            local human = part.Parent:FindFirstChild("Humanoid")
          game.ReplicatedStorage.ElectShock:Clone().Parent = human.Parent
		end
		wait (6)
		u = false
	end
end)

It works in paper, but when I test it, I get an error: Workspace.Electt.slowDamage:7: attempt to index nil with ‘Parent’

well I don’t know why, but some times it works some times it doesn’t.

You never checked if the parent of the parameter ‘part’ has a humanoid?
try this
if not u and part.Parent:FindFirstChildOfClass("Humanoid") then

1 Like

Oh, it was just that?!?! Thanks mate!