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

How do i make a script that plays a sound when my player has been damaged?

Hello, I would like to know how to make a script that plays a sound when the player has been damaged by anything, like in the script you have a roblox id and you enter the of number of the search number of the sound. Something like when damaged play sound? Thanks for helping me.

1 answer

This is a help forum, not a request site. However I would still try using a script along the lines of:

-- StarterCharacterScript
hum = script.Parent.Humanoid
last = hum.Health
mysound = Instance.new("Sound", script.Parent)
mysound.SoundId = 1337 -- Sound ID
hum.Changed:Connect(function()
	if hum.Health ~= last and hum.Health < last then
		print("i've been damaged!")
		mysound:Play()
	end
last = hum.Health
end

This script checks to see if the health is less than it was before. If it works let me know please!

1 comment

0

You should use the HealthChanged event instead of the Changed event

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