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

How to create a kill part?

Asked by 3 years ago

I've tried scripting a kill part but no success. My code is:

local part = script.Parent  

part.Touched:Connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character
    local hum = character:FindFirstChild("Humanoid")
    if hum then
        hum.Health = 0
    end
end)
0
Man,you should use ToolBox. Gigaset39 111 — 3y
0
Is this in a Script or LocalScript? AwesomeGamer2223 105 — 3y
0
It's a local script inside the part Mafincho 43 — 3y
0
try using a script,not a localscript. Gigaset39 111 — 3y

3 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
local Part = script.Parent

function onTouched(hit)

    if hit and hit.Parent then

        local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")

        if humanoid then

            humanoid:TakeDamage(0) --Change this number to your damage with each touch
        end
    end
end

Part.Touched:Connect(onTouched)

Sorry, I'm bad at explaining. You have to be sure that this is a server script and not a local one.

0
Thank you! It worked! Mafincho 43 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Since there are godmode exploit scripts out there, I'd recommend doing it this way:

script.Parent.Touched:Connect(function(hit) --Checks if the part has been touched
    if hit and hit.Parent:FindFirstChild("Humanoid") then --If the thing that touched it has a Humanoid, it'll fire script below.
        local NeckBind = hit.Parent:FindFirstChild("Head"):FindFirstChildWhichIsA("Motor6D") --Checks for the Motor6D that connects the Head to the Neck.
        if NeckBind and NeckBind.Name == "Neck" then --If there's a Motor6D called Neck then
            NeckBind:Destroy() --Destroys Neck Motor6D
        else --If there's no Neck Motor6D
            hit.Parent.Humanoid.Health = 0 --Changes health to 0, Kills player.
        end)
    end)
end)

I don't know if this will work, I will check later and edit this with a working script.

0
Hey, thanks for explaining each line! Unfortunately, it didn't work. I tried it on few other parts but no success. Mafincho 43 — 3y
0
it works perfectly, just delete the ) fom line 8 and from line 9. Gigaset39 111 — 2y
Log in to vote
0
Answered by
Gigaset39 111
3 years ago
Edited 2 years ago

In a part put that script:

      script.Parent.Touched:connect(function(hit)
          if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
              hit.Parent.Humanoid.Health = 0
             end
            end)
0
Sadly, that didn't work either. Mafincho 43 — 3y
0
i just tyed it, it works. Gigaset39 111 — 2y

Answer this question