Best way to save table data to player instance?

Hey guys! I started working on Data storage on my animal game, what i did is i save the player data in a folder called “PlayerData” for every player in the server, and inside that folder i put in some int values to save the currency, that way i can take the data from another script.

But recently i got confused on how can i save table data as i did

["OwnedAnimals"] = {"Komodo Dragon","Spotted Hyena","African Lion"}

I’m making the owned animal table list, and i wanna save it in the PlayerData folder so i can easily check if the player does/doesn’t have an animal
I did find a way but i dont know if its the best/pratical way i can do this, its basically creating another folder called OwnedAnimals, and then doing a in pairs loop on the OwnedAnimals data and create a string object for each animal

Does anyone know a better way? Any help appreciated!

You could save it as a string with each variable name separated by a special character such as the comma

1 Like

How would i get the individual animals apart and check if i have a certain animal?

Use string.split(stringhere, “specialcharhere”) to recreate your table

1 Like

Oh, i think that would work. But how would i add for example: The Tiger as another owned animal to the list?

Concatenate the string with “,The Tiger”

1 Like

Ok, i’ll try your solution. I’ll message you to see if it works, thanks!

1 Like

Just a quick question, do you know how i can take away the comma from the start of the string? Since now its like this: “,komodo,tiger” and it creates an empty value from the table

When creating the string just set the initial string to the first value for convenience.

Otherwise you’d have to perform string manipulation with string.sub and string.len

1 Like

You really helped me out! Thanks for answering, i can now continue on my datastorage system

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.