Kill block problem

Ok so im making an exploding block that kills you but i made the kill script here it is ```

function onTouched(part)
local h = part.Parent:findFirstChild(“Humanoid”)
if h~=nil then
h.Health = h.Health-100
end
end
script.Parent.Touched:connect(onTouched)

so i added wait(2) so it waits 2 seconds because the effects take a second to start or two but it doesnt work heres the entire script

wait(2)
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
h.Health = h.Health-100
end
end
script.Parent.Touched:connect(onTouched)

Hi, can you add more information? What exactly should it do vs. what is it doing incorrectly now?

its supposed to wait 2 seconds before it kills the human but it insta kills them

Put your wait(2) inside the onTouched function before you subtract the health

i did
look at my script it has wait(2) and it doesnt work

Okay, so if you want a function to wait every time, you’ll have to nest the wait call within the actual function. Like so:

function onTouched(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        wait(2)
        h.Health = 0
    end
end
script.Parent.Touched:connect(onTouched)

This way, we only make a call to the wait function after we know for sure that there is a humanoid. Additionally, I’d recommend setting the Humanoid Health to 0, or using the :BreakJoints() method on the humanoid would also be a more surefire way.

1 Like

ooooooh thanks man im really new to scripting so people like you help

1 Like