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