Sound Script Not Working

I’m making a “Murder” game and whenever you stab a humanoid, with a knife tool, it kills the player but doesn’t play the sound… Also, how do I stop it from spamming the sound? This is probably one of the easiest problems to solve…

Script:

local sound = script.Parent.Parent.Sound

function onTouch(handle)
local humanoid = handle.Parent:FindFirstChild(“Humanoid”)
if (humanoid ~= nil) then
humanoid.Health = 0
sound:Play()
end
end
script.Parent.Touched:Connect(onTouch)

I’ve searched for a little, for similar problems, and found nothing…

Let’s start off with some of the more obvious solutions to your sound issue.

  • Is your in-game volume turned up? [color=cyan]It should be.[/color]
  • Is the sound instance’s volume set to 0? [color=cyan]It shouldn’t be.[/color]
  • Is the sound’s parent set to a part? [color=cyan]It should be.[/color]
  • Does your sound have a proper sound ID in it? [color=cyan]It should.[/color]

It may also have difficulty playing because of the potential sound-spam issue. Check below.


Secondly, if you want to prevent potential sound-spamming, add a check for the humanoid’s health if it’s already dead:

local sound = script.Parent.Parent.Sound

function onTouch(handle)
local humanoid = handle.Parent:FindFirstChild(“Humanoid”)
if humanoid and humanoid.Health~=0 then --Notice the changes here.
humanoid.Health = 0
sound:Play()
end
end
script.Parent.Touched:Connect(onTouch)
1 Like

Thank you, I was too busy trying to figure out what ways I can make it work that I mistakenly left the audio ID blank, after I gave up and deleted it, then brought it back to try once again, with different ideas…

1 Like