The killbrick gives the error attempt to index local 'humanoid' (a nil value), what did I do wrong?
function onTouch(hit) local humanoid = script.Parent.Parent:FindFirstChild("Humanoid") humanoid.Health = 0 end script.Parent.Touched:Connect(onTouch)
Here it is correctly lol I saw you rushed so ill give it here:
function onTouch(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then --This will only run the conditional if humanoid exists. humanoid.Health = 0 end end script.Parent.Touched:Connect(onTouch)
ther, now that works
What's happening is it's hitting some random block and trying to find a humanoid.
After this, FindFirstChild returns nil. Then you tried to index "Health" for nil. 'Causing the error.
function onTouch(hit) local humanoid = script.Parent.Parent:FindFirstChild("Humanoid") if humanoid then --This will only run the conditional if humanoid exists. humanoid.Health = 0 end end script.Parent.Touched:Connect(onTouch)
Also, I think you put one too many ".Parent"'s as well. So you might want to look into that.