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

Problem with this script?

while true do
	if game.Players.LocalPlayer.Character.Humanoid:TakeDamage() then
	script.Parent.Parent.Sounds.Hurt:Play()
	end
end

1 comment

0

:TakeDamage(n) is a method that takes damage n from the Humanoid, not checks if damage was taken.

1 answer

✓ Accepted answer

The TakeDamage method is used to well, take damage. You would put a number as a parameter and the Humanoid would take damage. You need to use the Changed event.

game.Players.PlayerAdded:connect(function(p)
	repeat wait() until p.Character -- You could also use the CharacterAdded event. I for some reason did it this way
	hum = p.Character.Humanoid
	old = hum.Health
	hum.Changed:connect(function()
		if (hum.Health < old) then
			script.Parent.Parent.Sounds.Hurt:Play()
			old = hum.Health
		end
	end)
end)

The above script was actually tested and should work perfectly.

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