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

How to make a kill block to kill player?

I'm really new in scripting.

I started my first game and it have a kill block, when player touch it, it should kill the player.

My code:

local trapPart = script.Parent
 
local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		-- Set player's health to 0
		humanoid.Health = 0
	end
end
trapPart.Touched:Connect(onPartTouch)

I have no idea why this doesn't work, can you help me?

2 answers

✓ Accepted answer

Lol, that script is outdated.

You should use this instead:

script.Parent.Touched:Connect(funtion(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:BreakJoint()
	end
end)

Anddd.. Boom, you are done. :)

1 comment

0

^

I think your script it's outdated so it didn't work for you.

Scripts that kill players were easy to do. So, let figure out how it works.

script.Parent.Touched:Connect(function(hit)

end)

Function 'hit' is a neutral function, so if the script's parent touched this will connect function 'hit'.

'end)' is a thing that automatically adds while your connect's bracket has a function.

script.Parent.Touched:Connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

	end
end)

Line 2 means if 'hit' and the parent (People) who touched and find a thing named 'Humanoid'.

'end' is used for ends the if...then statement.

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

Line 3 shows the people who touched will get the humanoid and make the health become 0.

I hope I helped, and thanks for reading patiently! I hope you have a nice day :D, bye!

5 comments

0

^

0

?

0

Upvote boi

0

What

0

I already upvoted ur question reeeEEeeE

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