Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid Death Sound Playing only on Spawn? [closed]

Asked by 10 years ago

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

Locked by Redbullusa, adark, EzraNehemiah_TF2, and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 10 years ago

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.

0
I already solved my problem, but thanks for the tips. SpazzMan502 133 — 10y
0
It isn't over-kill when you are preloading massive amounts of audio. EzraNehemiah_TF2 3552 — 10y
Ad
Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

(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)