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

Does this code kill a Humanoid?

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

i need help with this code because when i jump on it, it doesnt kill me

6 comments

0

Where is the script located?

0

it is located right under the part so the part is the 'Parent'

0

I mean you could test it

0

i did and im not dying

1

So no...

0

Try and remove the 'If Hit and' part

2 answers

Just an add on to the above but explaining a little more about which does what

script.Parent.Touched:Connect(function(hit) --connect a function to when the block is touched

local humanoidcheck = hit.Parent:FindFirstChild("Humanoid") --make sure this is a player and not some random object

if humanoidcheck ~= nil then --if humanoid is not equal to nil (non existing) then

humanoidcheck.Health = 0 --kill the player

end

end)

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

if hit.Parent:FindFirstChild("Humanoid")then

		hit.Parent.Humanoid.Health = 0
	
	 end
end)

You just had a slight error in where you placed the " : " on :FindFirstChild(). You probably had something like, "FindFirstChild is not a member of hit" in your errors output.

No problem.

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