Attempt to index local 'file' (a nil value) at file:write
snippet in lua

Attempt to index local 'file' (a nil value) at file:write

user299

A = "Hello"
local file, err = io.open ('test.txt',"w")
if file==nil then
    print("Couldn't open file: "..err)
else
    file:write(A)
    file:close()
end