Do you have any solution on how to make a kill brick script?

Everyone is posting literally the same code over and over again.
The only thing wrong with the code you have is that you are calling GetPlayerFromCharacter with OtherPart, not OtherPart.Parent as it should be.

When a player touches the brick, it is usually one of their limbs that is touching, so the limb’s parent is the player’s character.

2 Likes

The problem with your code is you are treating OtherPart as the character. OtherPart is equal to the value of the part that touched the kill brick, for example the player’s right leg. When you try to get the player from the character, you are trying to get the player from the right leg, which is not the character. To get the character, you need to get the parent of OtherPart by typing OtherPart.Parent.

Your new code would look like this:

script.Parent.Touched:Connect(function(OtherPart)
	local player = game.Players:GetPlayerFromCharacter(OtherPart.Parent)	
	if player then
		player.Character.Humanoid.Health = 0
	end
end)

The traditional way of creating a kill script looks like this:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

hit.Parent is equal to the player’s character, so when you check to see if the character contains a humanoid, that means that a player has touched the part and not a random part flying around.

This is the easiest thing you can probably do:

local KillBrick = script.Parent

KillBrick.Touched:Connect(function(part)
local Humanoid = part.Parent:FindFirstChildOfClass("Humanoid") 
if not Humanoid then return end
Humanoid.Health = 0  
end)

Insert a part, then insert a script, the script should be a child of your part, then…
Code:

script.Parent.Touched:Connect(function(hit) --The function
	local Humanoid = hit.Parent:FindFirstChild("Humanoid") --Telling the game what Humanoid is
	if Humanoid then --This will trigger if what touched the part has a child named "Humanoid"
		Humanoid.Health = 0 --The amount of health it's set to.
	end
end)

Edit: If you have a larger scaled part, cancollide should be off as they cannot glitch it. (Not saying it’s impossible, and you can do this anyway.)

1 Like

how many times are you guys gonna post literally the same code on a 6 day old thread…

2 Likes

Well, he didn’t close the thread, so we are free to assume he still needs help.

If you have found a solution, please mark the solution as a solution.

script.Parent.Touched:Connect(function(part)
 if part.Parent:FindFirstChild("Humanoid") then
  part.Parent.Humanoid.Health = 0
 end
end)

Edit: Fixed error

1 Like

Please do not post similar replies when posting on the Developer Forum.