script.Parent.Touched:Connect(function(hit) if hit and hit.Parent.FindFirstChild("Humanoid")then hit.Parent.Humanoid.Health = 0 end
end)
i need help with this code because when i jump on it, it doesnt kill me
Just an add on to the above but explaining a little more about which does what
script.Parent.Touched:Connect(function(hit) --connect a function to when the block is touched local humanoidcheck = hit.Parent:FindFirstChild("Humanoid") --make sure this is a player and not some random object if humanoidcheck ~= nil then --if humanoid is not equal to nil (non existing) then humanoidcheck.Health = 0 --kill the player end end)
```lua script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
hit.Parent.Humanoid.Health = 0 end
end) ```
You just had a slight error in where you placed the " : " on :FindFirstChild()
.
You probably had something like, "FindFirstChild is not a member of hit" in your errors output.
No problem.