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

How to make something kill you only if a specific part of your body touches it?

Asked by 4 years ago
Edited 4 years ago

Hey so I just started scripting yesturday and I can make kill bricks now but I was wondering if a specific part of your body touches the kill brick then you die instead of the whole humanoid touching it. Here's my code so far:

local function onTouched(player)
    local humanoid = player.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid.Health = 0
    end
end

script.Parent.Touched:Connect(onTouched)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can check the part name

local function onTouched(player)
    local humanoid = player.Parent:FindFirstChild("Humanoid")
    if humanoid then
    if player.Name == "Head" then -- Check the part name, for example: Head
        humanoid.Health = 0
    end
    end
end

script.Parent.Touched:Connect(onTouched)
0
Thanks for the help! AtrocityPrevails 49 — 4y
Ad

Answer this question