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

I am trying to make a deathblock script that only kills me when I touch it?

I’m trying to learn scripting. It is very hard, and I tried to make this deathblock as a frist try. But something isn’t working as it should. I tried to make it so it only kills me when I touch it. I would be so thankful if someone is able to help me with my mistakes.

function kill(player)
	Player.Parent.Humanoid.Health = Player.Parent.Humanoid.Health == -100
	Script.Parent.Touched.Connect(kill)
end

2 answers

✓ Accepted answer

So what you need to do is get the Humanoid from the player that touches the brick.

function kill(player)

won't work. If you're going to kill the Humanoid, you must identify it. Here's a script that fixes your mistakes.

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

Hope this helped you.

2 comments

0

It did! Thank you. This defenently helped me with my scripting! :)

0

Nice, although I think the "and" isn't necessary to make a kill script. You can just use break joints.

DeathBlock script [kills everyone that touches it]:

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

DeathBlock script [ONLY KILLS YOU!]


local Name = "PlayersUsername" -- This will be the only player that can die by touching the brick

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

Hope this helped!

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