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

Why won't my random death sound script work, what else am I doing wrong?

Asked by 4 years ago
01function addSound()
02 
03    local sounds = script:GetChildren()
04    local chosenSound = sounds[math.random(1, #sounds)]
05    local soundCln = chosenSound:Clone()
06    soundCln.Parent = script.Parent.Head
07    soundCln.Name = "DeathSound"
08    soundCln:Play()
09 
10end
11 
12if script.Parent.Humanoid.Health == 0 then
13    addSound()
14end

No errors, nothing. The solution is probably just in my face but I'm not too good with scripting yet. Help would be appreciated.

1 answer

Log in to vote
2
Answered by
Ludzik78 136
4 years ago
Edited 4 years ago

Try doing: script.Parent.Humanoid.Died:Connect(addSound)

0
Thanks a bunch, it works like a charm mrfrank79 30 — 4y
0
No problem! :P Ludzik78 136 — 3y
Ad

Answer this question