I am trying to make and code killbrick for my upcoming obstacle course. The only part of the code I know is :
local trapPart = script.Parent
Please stay tuned for my new obby.
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
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