I've tried to do it but it doesnt work and theres no error in output. my script: script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.BreakJoints() end end)
COMMUNITY QUESTION
How do I make it so whenever a player touches a part, it kills the player?
2 answers
Heyo! I can help! This is my 1st time on scripting helpers.
Normal Method
--Script written by ericboyjuly2010
script.Parent.Touched:Connect(function(hit)
if hit:IsA("Part") or hit:IsA("MeshPart") or hit:IsA("UnionOperation") or hit:IsA("Accessory") then
local H = hit.Parent:WaitForChild("Humanoid")
if H then
H.Health = 0
end
end
end)
Folder Method (Also named my folder kill parts)
--Script written by ericboyjuly2010
for _,kp in pairs(game.Workspace.KillParts:GetChildren()) do
kp.Touched:Connect(function(hit)
if hit:IsA("Part") or hit:IsA("MeshPart") or hit:IsA("UnionOperation") or hit:IsA("Accessory") then
local H = hit.Parent:WaitForChild("Humanoid")
if H then
H.Health = 0
end
end
end)
end
-- actual use of .touched to kill anything that has joints
local p = Instance.new("Part",workspace)
p.Touched:Connect(function(p)
if p.Parent:IsA("Model") then
p.Parent:BreakJoints()
else
if p.Parent:FindFirstChildOfClass("Humanoid") then
p.Parent:FindFirstChildOfClass("Humanoid").Health = 0
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
konnichiwa! V ;3