Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me fix this "ontouched" kill script?

function hit (h)

if h.Parent:findFirstChild("Humanoid") then

	if h.Parent.Humanoid.Health ~= 0 then 

		h.Parent.Humanoid.Health = 0

			end 

		end

	end

game.Workspace.Part.Touched:connect(hit) 

This is suppose to kill anyone that touches the parent of this script.

Please help.

Thanks.

2 comments

0

Please edit your post to 1) use the Lua code formatting functionality. 2) Make your title mean something specific to the question. 3) Provide what output and debugging you have done.

0

Ok, I will in future

1 answer

Hmm...everything looks perfectly fine. Make sure you don't have more than 1 object named "Part" in the workspace or else you could just be touching the wrong one. Also, make sure that the last line properly connects the function to the object. Hope this helps. Leave a comment if you still have a problem with this.

7 comments

0

That won't make a difference.

0

It's also best to check for the existence of h.Parent. [Redacted, reread original]

0

I realized that.

0

Fixed it :P

0

Thanks guys but I managed to fix it, I changed game.Workspace.Part.Touched:connect(hit) to game.Workspace.Wall.Touched:connect(hit). Wall is the name of the parent. Thanks for the help anyway.

0

You mean wall is the name of the part? Because if you want the parent you can just do 'script.Parent'.

0

Yes, the part name, thanks for the help. I will try the script.Parent thing

This discussion is preserved as it was. New answers, comments, and votes are closed.