Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i code a killbrick system?

Asked by
goodlead -62
4 years ago

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.

0
How do I get more reputation? goodlead -62 — 4y
0
Learn the basics please. AntiWorldliness 868 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

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

0
Thanks a lot!!! goodlead -62 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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
0
Thanks A Lot ScriptsALot!!! lol goodlead -62 — 4y
0
Accept and upvote if works please ScriptsALot 91 — 4y
0
How do I upvote? I am new. goodlead -62 — 4y
0
I think you need a certain amount of reputation to upvote. ScriptsALot 91 — 4y
0
Oh ok. goodlead -62 — 4y
Log in to vote
0
Answered by
goodlead -62
4 years ago

Thank you all for your help!!

0
np ScriptsALot 91 — 4y

Answer this question