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

How would I kill a player only if their head touches a part?

Asked by 6 years ago

So I've tried multiple ways to mess around with onTouch and finding the humanoid, but I wasn't quite able to make a kill brick that only kills a player if it touches their head. When attempting and asking people, they've told me I was way off. Could someone please help me out?

1 answer

Log in to vote
1
Answered by 6 years ago

Hey Supergamerboy1995,

What you are asking for is quite simple when understood. You just need to use the .Touched event, and the parameter of that event is the part that touched. Then, you check if the part's name is "Head" Well, it's easier to show rather than just talk about it, so here is my script, I'll explain it line by line.

Script to kill people if the part touches their head

local part = script.Parent; -- The part that will be touched.

part.Touched:Connect(function(obj) -- The anonymous function for the touch.
    local hum = obj.Parent:FindFirstChild("Humanoid"); -- The humanoid that could be found in the part's parent.
    if obj.Name == "Head" and hum then -- Checks if the name is "Head" and checks if the humanoid exists.
        -- Kill player
    end -- end for if statement
end) -- end for function

Well, I hope I helped, and have a nice day.

Thanks,

~~ KingLoneCat

0
If the place has projectiles, one should always make sure "obj.Parent" exists before using it (ie start of line 4 should then be "local hum = obj.Parent and ...") chess123mate 5873 — 6y
0
The parent will always exist if the part is able to be touched. KingLoneCat 2642 — 6y
0
Oh! When explained that seems simple to understand, thanks! Supergamerboy1995 129 — 6y
0
No problem. KingLoneCat 2642 — 6y
Ad

Answer this question