How to stop errors from showing up after a script works

I made a script that works, but it creates constant errors after it works

image

image
How do I stop the errors?

Use pcalls. Something like this.

local function onTouch(part)
    local success, error = pcall(function(part)
        -- do the function stuff here
    end)
end

I would advise you to just solve the error.

How do I solve it? It happens after the player is dead

Try something like this?:


local function onTouch(part)
	local head = part.Parent:FindFirstChild("Head")
	local Humanoid = part.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		Humanoid.Health = 0
		if head then
			if head:FindFirstChild("Attachment") then
				head.Attachment:Destroy()
			end
		end
	end
end
	
	
script.Parent.Touched:Connect(onTouch)
1 Like