How would I possibly make a table useable by all scripts? Like how you can have bool values and number value objects to save data and use it in GUI’s. My question in how would I do the same to tables because I want to save cars owned by the player and allow them to spawn them if they own them. I also need help with saving the owned cars to the datastore if possible.
I mean, you could put these tables in a module and then just require module from different scripts and you can just save a table with datastores too.
First thing, save and load data of Tables is the best thing I made in my life as a developer.
How you do this?
local ServerData = {}
--EventToSaveCar(Player)
local PlayerData = { ["Cars"] = {"MyFirstCar", "MySecondCar", "MyThirdCar"}
ServerData[Player] = PlayerData
--EndOfEvent
Or you can save cars upgrade too.
--EventToSaveCar(Player)
local PlayerData = {
["Cars"] = {
["MyFirstCar"] = {"Nitro"},
["MySecondCar"] = {"Tires"},
["MyThirdCar"] = {"Engine"}
}
ServerData[Player] = PlayerData
--EndOfEvent
To get tables, add and edit is easy.
local PlayerSpecificData = ServerData[Player.Name]
PlayerSpecificData = table.insert(MyFourthCar = {})
Or
local PlayerSpecificData = ServerData[Player.Name]
PlayerSpecificData.MyFourthCar = {"Nitro"}
This looks great! I didn’t even know that was a thing. And just a question, I can save this to a data save right? Also I keep getting an error that the table doesn’t exist. This is able to be pulled into other scripts right?
Yes. I show you a bit of my own datastore.
Here we see my ServerData [Table]
And here we load SpecificPlayerData [Table]
Here we put SpecificPlayerData inside ServerData[Player.Name]
And here we save table
Obs: NewSaveData
So I can pull the table into another script, or will I have to fire client/server?
I had this doubt yesterday
But ye we can pull.
I thought that when we pull a table, we duplicate him but not.
We call his ID, like a TABLE ID.
And when you change the table inside Script1, if Script2 has access to that table, will change too.
(Sorry if sentence is weird, I’m studying english at moment).
Thank you so much, and don’t worry, your English is very good!