The killbrick gives the error attempt to index local 'humanoid' (a nil value), what did I do wrong?
1 | function onTouch(hit) |
2 | local humanoid = script.Parent.Parent:FindFirstChild( "Humanoid" ) |
3 | humanoid.Health = 0 |
4 | end |
5 | script.Parent.Touched:Connect(onTouch) |
Here it is correctly lol I saw you rushed so ill give it here:
1 | function onTouch(hit) |
2 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
3 | if humanoid then --This will only run the conditional if humanoid exists. |
4 | humanoid.Health = 0 |
5 | end |
6 | end |
7 | 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.
1 | function onTouch(hit) |
2 | local humanoid = script.Parent.Parent:FindFirstChild( "Humanoid" ) |
3 | if humanoid then --This will only run the conditional if humanoid exists. |
4 | humanoid.Health = 0 |
5 | end |
6 | end |
7 | 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.