Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how would i save multiple items in a folder?

function getitems(plr)
	local holder = game.ReplicatedStorage:FindFirstChild(plr.Name.."'s Items Holder"):GetChildren()
	for i,v in pairs(holder) do
		if v.ClassName == "StringValue" then
			if v.Name ~= "Value" and v.Value ~= "" then
				local id = game.Players:FindFirstChild(plr.Name).userId
				itemDataStore:SetAsync(id..":items", v.Value)
			end
		end
	end
end
	local getitems = itemDataStore:GetAsync(newplayer.userId..":items")
	if getitems == nil then
		print(newplayer.." Has No Items!")
	else
		local newitem = Instance.new("StringValue")
		newitem.Name = getitems
		newitemValue = getitems
		newitem.Parent = game.ReplicatedStorage:FindFirstChild(newplayer.Name.."'s Items Holder")
	end

im trying to save multiple values in a folder in replicated storage but this current script only saves 1 of those values not all of them. im pretty new to datastore and scripting in general. any help appreciated TY.

1 comment

0

You could store the values in a dictionary, with the index being the value's name and value being the actual value. An example being {["Cash"] = 100, ["Level"] = 5}. Once you have the dictionary created, save it to the Datastore. NOTE: You may have to use JSON Encoding/Decoding for the dictionary.

1 answer

✓ Accepted answer

You're trying to save each item individually which is overwriting it each time

Instead you should be putting all of the strings into a table and then save the table

when you load the table, simply loop through it and put it back into the folder

2 comments

0

yea idk how to put all the stings into a table and save the table lol. ama try searching it up on wiki or something when im on tomorrow. ty for the help

0

Thanks it helped me alot learned how to work with tables and everything and now it works.

This discussion is preserved as it was. New answers, comments, and votes are closed.