Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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.

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. BlueTaslem 18071 — 10y
0
Ok, I will in future space482 0 — 10y

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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.

0
That won't make a difference. Perci1 4988 — 10y
0
It's also best to check for the existence of `h.Parent`. [Redacted, reread original] BlueTaslem 18071 — 10y
0
I realized that. dyler3 1510 — 10y
0
Fixed it :P dyler3 1510 — 10y
View all comments (3 more)
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. space482 0 — 10y
0
You mean wall is the name of the part? Because if you want the parent you can just do 'script.Parent'. Perci1 4988 — 10y
0
Yes, the part name, thanks for the help. I will try the script.Parent thing space482 0 — 10y
Ad

Answer this question