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

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

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

✓ Accepted answer

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)

1 comment

0

Thanks for the help!

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