How to create data storage

Hello there,

I would like to know what would be the ideal data storage for the server - for saving user data like what vehicles he has, guns, money, …

I was thinking something like a JSON file system - a dedicated folder with lots of json files (users, vehicles, houses, …)

Thank you.

Most developers use an sql database and use the mysql-async resource.

You can use the built in KVP Database on the server/client search kvp on on the FiveM native reference for how to use them.

Ok I have just set up a mysql database and now I am using Mysql.Data.MySqlClient; in my Visual Studio client script to acces the data. The problem is that I don’t know how to add the MysqlClient reference to the FiveM server. Do I need to put all the .dll files that i get in the Debug folder inside my client resource folder?

To be honest it would be way simpler just to use mysql-async.

All you need is the resource the way it is and call tables and rows by the identifier. It’s super simple. It also has great documentation on it as well.

Edit: The documentation explains it but an example of how you’d use it.

RegisterNetEvent(“example”)
AddEventHandler(“example”, function()
Local identifier = GetPlayerIdentifiers(GetPlayerPed(-1))

MySQL.ready(function()
     MySQL.async.fetchAll("SELECT * FROM example WHERE identifier = '"..identifier.."'")
     end)
end)

end)

Kinda a bad example but I’m on my phone so it’s the best I can do for now.

Is there any downside to using the built-in ResourceKvp system rather than a mySQL database? I’ve worked with both, but most the devs on here tend to use mySQL. Is there a reason behind that? (security, effectiveness, etc.)

Well, once the cache is removed the variables are also destroyed. Take VMENU outfits for example, upon a client-side cache wipe the outfits are removed. MySql/smss are persistent.