|
| 08 Apr 2016 10:47 AM |
So, I want to save values every time they're inserted into a folder. For convenience, they're all string values. I want to then, when the player next joins the game, insert all these values into the folder. Example:
Player 1 collects item "Apple" Player 1 collects item "Sword" Player 1 collects item "Orange"
^ These are all inserted into a folder.
When the player leaves, I want it to save:
"Apple" "Sword" "Orange"
and then the next time they join, their inventory loads as
"Apple" "Sword" "Orange"
...
The problem for me is when they then collect another item, say, "Fire torch".
How do I save the inventory without overwriting the current one? It's really easy, I'm sure. I just can't think how. And also, how do you just save lists like that? I know how to precreate lists in datastores and then check whether they've collected that, but my inventory is infinite and so I can't just have "Item 1" "Item 2" etc. It's also inefficient if I add new items into the game.
|
|
|
| Report Abuse |
|
|
|
| 08 Apr 2016 10:51 AM |
I don't think I fully understood what you meant, but you could just do this:
local collecteditems = ds:GetAsync(key) --returns for instance {"Apple", "Sword", "Orange"}
function CollectItem(item) table.insert(collecteditems, item) end
CollectItem("Fire torch") --Now collecteditems = {"Apple", "Sword", "Orange", "Fire torch"}
ds:SetAsync(key, collecteditems) |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2016 10:57 AM |
That looks like it's on the right lines, thanks. And, I'm not too good with tables. Where it retrieves the different items, how do I create a value for each of them?
Like,
for i = 1,#collecteditems do value = Instance.new("Value, player") value.Name = collectitems end
|
|
|
| Report Abuse |
|
|
|
| 08 Apr 2016 11:01 AM |
for k,v in pairs ( collectedItems) do local val = Instance.new ("StringValue",player) val.Name = k end
#Strikin' |
|
|
| Report Abuse |
|
|
| |
|
3DReality
|
  |
| Joined: 08 Mar 2015 |
| Total Posts: 150 |
|
|
| 08 Apr 2016 11:06 AM |
The best way I would do it is. Save each item as a number value. The name will be the item its representing and the value will be equal to how much. Because how are you going to determine apple 1,2,3,4,5 ect?
So what I would do is make a folder call it "Holding". Now what you would do is each time a child is added see if player already has that item. If not create it and save it. If so just add +1 to the value. For example
Holding.ChildAdded:connect(function(check) local inventory = player.Inventory if inventory:FindFirstChild(check.Name) ~= nil then print("Item exists and is not nil") --Add +1 to value elseif inventory:FindFirstChild(check.Name) == nil then print("Item is nil") --Make a new instance of the item. Set value to 1. end end) ~If there is a typo my bad ;C I know I did not define the variables ~ Then you can either set up the save script withing the elseif or you can do it in a whole different script when a child is added to inventory
Now for loading I would make a table of all possible items. Run a search if finding the item doesn't come up nil place it via player.inventory. If you dont fully understand what I am trying to get at I am sorry just woke up. I can maybe make you a example/start script on how you would do this
Also remember if your game is FE ~FilterEnabled you cant save via player 'At least I believe so' So you would half to run RemoteFunctions
|
|
|
| Report Abuse |
|
|