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

Humanoid Death Sound Playing only on Spawn?

So I have a sound in a Monster's head in workspace. When the humanoid of that monster dies, the sound plays.

The problem is that it only plays when the Monster spawns, and not when it dies.

Here's the script

if script.Parent.Parent.Humanoid.Died then
	


	script.Parent.Roar:Play()
	
end

I ALSO have A script that preloads the sound, which is

Assets = {131172401}
 
for _, asset in ipairs(Assets) do
     Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
end

2 answers

✓ Accepted answer

I have a Test Dummy which you can use. There is a script inside that plays a sound when the humanoid health is 0. You can edit it to your use.

Also, you dont need pre-load scripts for audio. Its kinda over-kill.

2 comments

0

I already solved my problem, but thanks for the tips.

0

It isn't over-kill when you are preloading massive amounts of audio.

(I know that you already solved your problem, but I want to explicitly answer it for the sake of curious readers.)

Use the died event to fire the function specifically for playing the sound. You can do this with a separate connection line, or anonymously (meaning no name).

Separate Connection Line:

function MonsterDead()			-- function 'MonsterDead' with no arguments
	script.Parent.Roar:Play()		-- Plays the sound
end

script.Parent.Parent.Humanoid.Died:connect(MonsterDead)	-- When the humanoid dies, MonsterDead is triggered

Anonymously:

script.Parent.Parent.Humanoid.Died:connect(function ()		-- There's no name on this function; basically a function in the connect method (making the function the argument of the connect method)
	script.Parent.Roar:Play()		-- Plays the sound
end)

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