Working script with an error?

I made a script that destroys whatever tool your holding, but I keep getting the error

Workspace.Part.Script:2: attempt to index nil with 'FindFirstChild

Here is my script:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local tool = hit.Parent:FindFirstChildOfClass("Tool")
		if tool then
			tool:Destroy()
		end
	end
end)
1 Like

It means that hit.Parent doesn’t exist. All you need to do is add if not hit.Parent then return end at the start of that function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.