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

How do I make it so whenever a player touches a part, it kills the player?

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)

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

1 comment

0

konnichiwa! V ;3

-- 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.