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

How do I make a part kill the person that has touched it

Asked by 10 years ago

I have tried this and it didn't work :C please help me with this

function hit (h)
    h.health = 0
end

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

and the output said "health is not a valid member of part" or something

2 answers

Log in to vote
4
Answered by 10 years ago

Health is not a member of part, it is a part of Part.Parent.Humanoid

function hit (h) 
    if h.Parent:findFirstChild("Humanoid") then
        if h.Parent.Humanoid.Health ~= 0 then --Kinda a debounce
            h.Parent,Humanoid.Health = 0
        end 
    end
end
game.Workspace.Part.Touched:connect(hit) 
1
It is not recommended to Cap lock here, and no problem :P FromLegoUniverse 264 — 10y
0
On line 4, you did h.Parent,Humanoid instead of h.Parent.Humanoid, and you didn't capitalize Health. Thewsomeguy 448 — 10y
0
:P FromLegoUniverse 264 — 10y
Ad
Log in to vote
-8
Answered by 10 years ago

Health isn't actually a thing in your character, it's the Humanoid.

0
The thing touching it wouldn't be your character, it would be a part of your character, such as your left leg. Thewsomeguy 448 — 10y

Answer this question