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

How do you make something hurt the player who touches it?

Sort of embarrassing but I'm lost. I'm trying to figure out how to make a brick hurt whoever touches it but I don't know the word. To access the humanoid health I used:

Health=game.Players.player.Humanoid.Health but it said player is not a child of Players

1 comment

0

You can not Minus rep random people, for a start.

1 answer

✓ Accepted answer
function onTouch(part) 
	local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then	-- if a humanoid exists, then
		humanoid.Health = 0	-- "0" kills the player, you can change how much the brick damages the player.
	end 
end

script.Parent.Touched:connect(onTouch)

Hope it helps !

1 comment

0

Um, I'd change line 4 because then it'll automaticly kill the player, try 'humanoid.Health=humanoid.Health-Damage'

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