ERROR lua/test.lua:4: attempt to call field 'PlayFile' (a nil value)

70 views Asked by At
local AudioSource = nil

hook.Add("EntityTakeDamage", "UniqueNameForYourScript", function()
    sound.Play("sound/hurt1.mp3", "", function(source, err, errname)
        if IsValid(source) then
            AudioSource = source
            source:Play()
        else
            print("Error playing sound: " .. errname)
        end
    end)

    print("OW!")
end)

thats the script i used for glua and it says

"[ERROR] lua/test.lua:4: attempt to call field 'PlayFile' (a nil value)"

When i try to run it

i tried to run it. it didnt work

1

There are 1 answers

0
Luiggi33 On

It would be good to know, how you run the script.

I will assume that you are running it via the console command lua_openscript, which executes a script serverside. Its important to notice that sound.PlayFile is not available on the serverside. You either need to network this to the client or change your code to not use that function.

In addition to that, your code is missing some key options like a Vector for the position at the second argument.