generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Saving values as they're created

Previous Thread :: Next Thread 
Zarkonan_Zenheart is not online. Zarkonan_Zenheart
Joined: 29 May 2012
Total Posts: 610
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
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
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
Zarkonan_Zenheart is not online. Zarkonan_Zenheart
Joined: 29 May 2012
Total Posts: 610
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
ElectoStriking is not online. ElectoStriking
Joined: 10 May 2014
Total Posts: 1547
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
Zarkonan_Zenheart is not online. Zarkonan_Zenheart
Joined: 29 May 2012
Total Posts: 610
08 Apr 2016 11:03 AM
Thanks guys!


Report Abuse
3DReality is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image