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

How do i code a killbrick system?

3 answers

✓ Accepted answer

Hi,

Making a Killbrick is overly difficult. There are two versions I use the first being simpler, The second being more complex but gives a better chance of working.

Here is the first one (Simple)

--[[ I have included a breakdown of what each part does ]]--

local trapPart = script.Parent -- setting the name for the kill brick
trapPart.CanCollide = false -- makes the killbrick hit-able
 
local function onPartTouch(otherPart) -- function that finds what touched the killbrick
	local partParent = otherPart.Parent --finds the player
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") --finds the players health stats
	if humanoid then
		-- Set player's health to 0 aka killing them
		humanoid.Health = 0
	end
end
trapPart.Touched:Connect(onPartTouch)

Here is the second script (Advanced)

function stick(x, y)

	weld = Instance.new("Weld") 



	weld.Part0 = x

	weld.Part1 = y



	local HitPos = x.Position



	local CJ = CFrame.new(HitPos) 

	local C0 = x.CFrame:inverse() *CJ 

	local C1 = y.CFrame:inverse() * CJ 



	weld.C0 = C0 

	weld.C1 = C1 

	

	weld.Parent = x

end



function onTouched(part)

	local h = part.Parent:findFirstChild("Humanoid")

	if h~=nil then

wait(0.001)
h.Health = 0
children = h.Parent:children()

	for i=1,#children do

		if(children[i].className == "Part" and children[i].Name ~= "Torso") then stick(children[i], h.Parent.Torso) end

		if(children[i].className == "Hat") then stick(children[i].Handle, h.Parent.Torso) end

	end

	h.Parent.Head.Velocity = h.Parent.Head.Velocity + Vector3.new(5,0,0)

	end

end



script.Parent.Touched:connect(onTouched)

hope this helps ????

If this is what you are looking for, please click accept answer so the site knows that it has been answered

1 comment

0

Thanks a lot!!!

You don't need the local trappart. You can just do this.

local function onTouched(hit) --The function
	local h = hit.Parent:FindFirstChild("Humanoid") --This is the humanoid
		if h then --This checks for a humanoid
			h.Health = 0 --This removes the humanoid's healthh
		end
	end)

script.Parent.Touched:Connect(onTouched) --This activates the function

5 comments

0

Thanks A Lot ScriptsALot!!! lol

0

Accept and upvote if works please

0

How do I upvote? I am new.

0

I think you need a certain amount of reputation to upvote.

0

Oh ok.

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