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

How would I make a brick that will instantly kill the player when touched?

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild ("Humanoid")then
           hit.Parent:BreakJoints()
               end
          end

1 comment

0

This is the script for you guys to make a lava jump stage for your obby! put this script in the lava!!!

3 answers

✓ Accepted answer
function onTouch(part) 
	local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then	-- if a humanoid exists, then
		humanoid.Health = 0	-- damage the humanoid
	end 
end

script.Parent.Touched:connect(onTouch)

This should work:

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

Please contact me when this is not what you ment or if it doesn't work.

1 comment

1

Don't just assume that was it when no info was given. btw hit and hit.Parent will never be nil.

Since you only gave info in your title, I can only go off that. But, for what the title is asking, this is what I do:

script.Parent.Touched:Connect(function(hit)
	local Char = hit:FindFirstAncestorOfClass("Model")
	
	Char.Humanoid.Health = Char.Humanoid.Health - Char.Humanoid.Health
end

Obviously, this wouldn't work if you put another model in-between the character and hit. But the reason I do this, is because if an accessory touched the part, hit.Parent wouldn't work. So this way, it checks for the first model that hit is in.

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