Skinstashery
Roblox
Home / Roblox / Studio script library / Kill brick
RB-004

Roblox kill brick script

A part that hurts or kills any character that touches it.

Script type
Script
Where it goes
Inside the Part
Category
Hazards and pads

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Kill brick: put this Script inside the part that should hurt players.

local DAMAGE = 100        -- 100 kills a normal player (max health is 100)
local COOLDOWN = 1        -- seconds before the same character can be hurt again

local part = script.Parent
local recentlyHit = {}    -- humanoids that were just hurt

part.Touched:Connect(function(hit)
	local humanoid = hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid")
	if not humanoid or humanoid.Health <= 0 then
		return
	end
	if recentlyHit[humanoid] then
		return
	end

	recentlyHit[humanoid] = true
	humanoid:TakeDamage(DAMAGE)
	task.wait(COOLDOWN)
	recentlyHit[humanoid] = nil
end)

How to set it up

  1. In Studio, insert a Part (Model tab, Part). Make it red if you like.
  2. In the Explorer window, hover over the Part, click the plus button, and add a Script.
  3. Delete the default print line and paste the code.
  4. Press Play and walk onto the part.

Change it

More in Hazards and pads

All Roblox scripts

More Roblox tools