Hello! I am making a sword fighting game and need to store a sword inside of the datastore if possible. I was hoping to use this method but if It is impossible I will use another method in mind.
Also I apologize if this is under the wrong category.
Hello! I am making a sword fighting game and need to store a sword inside of the datastore if possible. I was hoping to use this method but if It is impossible I will use another method in mind.
Also I apologize if this is under the wrong category.
DataStores are only capable of storing tables and values. You could save all of a model’s part properties and load from that, but that’s likely not what you’ll be wanting to do.
First let me ask you, why do you want to store a sword inside of a DataStore?
You could possibly save the Object as a String
then when Loading up you can check if the Player owns the Object and If so you can give the Object to the player or do whatever is necessarily…
Well right now I’m working on like a shop and inventory so instead of putting all the swords in a folder and putting the folder in the player, I was planning on just storing the entire folder in the store but apparently I have to go with the option I just mentioned…
Save a bool value called sword, and if is true, it give the sword
Yeah, but I’d have too store the sword name as well,
So instead of bool value, save a string value with the name of sword, and if the name match, so you have the sword
You’ll likely want to use a table to store item names that the player owns.
you can save the name of the sword maybe
Alright so the new plan is going to be string values stored in a table in a store with the key of the userid of the owner player. There will be a pad in the game that upon touched will send the player into the arena and search for the value by the name “Equipped”. If there is a value by the name of “Equipped”, then it will hand the sword by the name of the value.
Do you mean to say that only one item needs to be saved at any given time?
No no. So the inventory is just a folder inside of the player, there will be some string values inside the folder, the string values will be named “Sword” and the value will be the name of the sword, however, there will be one string value inside of the inventory that’s named “Equipped”. All of the PHYSICAL swords will be parented by a server script, so when a player touches it(The pad), it will look through the touched player’s inventory folder to find the string by the name “Equipped” the value however will be the name of the sword. So the physical sword with the name of the strings value that’s named equipped will be given to the player.
So my plan WAS to store the entire folder instead of making a new folder and loading all the sword into it.
So to clarify, you mean that you will have an inventory of swords, but only one will be equipped?
Also, I would recommend not using physical storage for an inventory (the physical swords are fine, but not for the inventory).
Yes but then there will be an inventory UI where you can equip one of the swords you already own.
I would definitely recommend using a table rather than physical storage like that. Physical storage has a load time, which tables don’t.
For example:
local inv = {
Equipped = 'Iron Sword',
Inventory = {'Wood Sword','Iron Sword','Steel Sword'}
}
Or if you want a cleaner approach:
local inv = {'Wood Sword','Iron Sword','Steel Sword'}
inv.Equipped = 'Iron Sword'
Thanks but I plan to have multiple scripts referencing the inventory and therefor cannot use such a method.
Having multiple scripts reference a table is not a problem. Even across the client/server boundary.
How would I do that though? Filler