Kill Block Not Working

  1. What do you want to achieve?
    I want to make a kill block, but I am absolutely new to scripting and have only kind of an idea as to what I’m doing

  2. What is the issue?
    I’m trying to make a kill block, my code is below, but for some reason the script isn’t working and my character isn’t dying when I hit “Play Here” to test it

function ontouch(part)
	local hum = part.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		hum.Health = 0
	end
end

script.Parent.Touched:Connect(function(ontouch)
  1. What solutions have you tried so far?
    I’ve looked at the game Lua Learning’s user-submitted tutorial on how to make one, but it was essentially the same code and it still didn’t work
1 Like

Do you get any errors in the output, if so what do they say?

Very simple solution, this is the script that I usually use, and it works every time:

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)

Maybe just try humanoid:TakeDamage(humanoid.MaxHealth)?

That should work

Post below is solution V

The last line looks a bit strange. It reads:

script.Parent.Touched:Connect(function(ontouch)

While you start the function on top. Might want to change it to just

script.Parent.Touched:Connect(ontouch)
2 Likes

17:25:40.903 - Workspace.part.Script:8: Expected 'end' (to close 'function' at column 31), got <eof>

^ That’s the one I think is linked to the script in question (it’s in a test place with a few different scripts), and I think it is the functionpart of the last line that is causing it to not work

When I took that out, the following came up in the output following touching the block -

  17:31:56.192 - Workspace.part.Script:4: attempt to index nil with 'Health'

Update -

I got the script to work by taking out the function in the 8th line, and re-applying the ~ prior to the = in line 3. Thanks to all that helped me out with this one!

I only know basic scripting so for all I know, you obviously didn’t add an end bracket at the last line.

Since there was no start bracket in this script, no end bracket was required the only unneeded part of the script was the function in the last line. To work, it just needed to be changed to -
script.Parent.Touched:Connect(ontouch)

2 Likes

Remove this part function( from the script, and see what happens.

1 Like