local AudioSource = nil
-- Define a table of sound file names (without the path)
local soundFiles = {
"hurt1.wav",
"hurt2.wav",
"hurt3.wav",
-- Add more sound files as needed
}
hook.Add("EntityTakeDamage", "UniqueNameForYourScript", function(target, dmginfo)
-- Check if the target entity is a ragdoll
if IsValid(target) and string.find(target:GetClass(), "ragdoll") then
-- Choose a random sound file from the table
local randomSoundName = table.Random(soundFiles)
local soundPath = "sound/" .. randomSoundName
sound.Play(soundPath, target:GetPos(), function(source, err, errname)
if IsValid(source) then
AudioSource = source
source:Play()
else
print("Error playing sound: " .. errname)
end
end)
print("OW!")
else
print("Not a ragdoll")
end
end)
when i hit a ragdoll it says this in the console and i dont know what to do please help me
i was expecting to play a sound from the ragdoll