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

How to create a kill part?

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)

4 comments

0

Man,you should use ToolBox.

0

Is this in a Script or LocalScript?

0

It's a local script inside the part

0

try using a script,not a localscript.

3 answers

✓ Accepted answer
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.

1 comment

0

Thank you! It worked!

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.

2 comments

0

Hey, thanks for explaining each line! Unfortunately, it didn't work. I tried it on few other parts but no success.

0

it works perfectly, just delete the ) fom line 8 and from line 9.

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)

2 comments

0

Sadly, that didn't work either.

0

i just tyed it, it works.

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