[Lua] Is io.open not able to load in FiveM?

I am making a menu in which you can read a text file and it will make a vehicle menu. All is well, until I realized that the menu wouldn’t load. I ended up finding out that the menu wouldn’t load because of my line below

local open = io.open

Does FiveM not allow io.open? I know another way of loading this, but I just want to know if using io.open to read a text file was not able to load in FiveM, or if there was another line of code I could use to prevent this

io should work on the server, but not on the client side.

Use LoadResourceFile instead.

2 Likes

Alright, there was my issue, I was using it client sided lol

I’ll go ahead and try out LoadResourceFile and tell you how it goes

make sure that whatever file you want to read on the client side, is in the files section in your __resource.lua file

1 Like

Alright, so I went ahead and did what you recommended and I put down this

local file = LoadResourceFile("cars", "cars.txt")

I have got the menu to fully load now, which is great, but I have one question.
I am using the text file to read what is on the inside, so I went ahead and made a for loop

for line in io.lines(file) do
        //...
end

Problem is, using io.lines(file) doesn’t work, so is there any way to use ‘LoadResourceFile’ to read the text on the inside?

1 Like

See in the FiveM Native Reference, they call the result data (*char). I think it just gives you a big string.

Try something like this, https://stackoverflow.com/questions/19326368/iterate-over-lines-including-blank-lines

1 Like

It gives you the file contents as a string. Including newlines (\r and/or \n) so split that string by \r\n or \n and loop through the table that’s created.

1 Like