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 3 years ago
function addSound()

    local sounds = script:GetChildren()
    local chosenSound = sounds[math.random(1, #sounds)]
    local soundCln = chosenSound:Clone()
    soundCln.Parent = script.Parent.Head
    soundCln.Name = "DeathSound"
    soundCln:Play()

end

if script.Parent.Humanoid.Health == 0 then 
    addSound()
end

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
3 years ago
Edited 3 years ago

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

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

Answer this question