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:

01local part = script.Parent 
02 
03part.Touched:Connect(function()
04    local player = game.Players.LocalPlayer
05    local character = player.Character
06    local hum = character:FindFirstChild("Humanoid")
07    if hum then
08        hum.Health = 0
09    end
10end)
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
01local Part = script.Parent
02 
03function onTouched(hit)
04 
05    if hit and hit.Parent then
06 
07        local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
08 
09        if humanoid then
10 
11            humanoid:TakeDamage(0) --Change this number to your damage with each touch
12        end
13    end
14end
15 
16Part.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:

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

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:

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

Answer this question