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

How do I save added values of a folder in data store?

So, this is what I am trying to do: I am trying to add a new StringValue to the Items folder, but I don't know how to save the newly created String to load when you join. Any help would be nice! Here is my current script:

local player = game:GetService("Players")
local SS = game:GetService("ReplicatedStorage")
local DS = game:GetService("DataStoreService")

local data = {
	["Layer2"] =  DS:GetDataStore("Layer2"),
	["Soul2"] = DS:GetDataStore("Soul2"),
	["QI2"] =  DS:GetDataStore("QI2"),
	["Path2"] = DS:GetDataStore("Path2"),
	["TLayer2"] = DS:GetDataStore("TLayer2"),
	["Rep"] = DS:GetDataStore("Rep"),
	["Items"] = DS:GetDataStore("Items")
}


player.PlayerAdded:connect(function(plr)
	
	local success, err = pcall(function()
	local userID = plr.userId
		local Stats = Instance.new("Folder")
	Stats.Name = "PStats"
		local Layer = Instance.new("IntValue")
	Layer.Name = "Layer"
	Layer.Value = data["Layer2"]:GetAsync(userID)or 1
	
local Items = Instance.new("Folder")
Items.Name = "Items"

	local Soul = Instance.new("IntValue")
	Soul.Name = "Soul"
	Soul.Value = data["Soul2"]:GetAsync(userID) or 1
		
		local TLayer = Instance.new("IntValue")
		TLayer.Name = "TLayer"
		TLayer.Value = data["TLayer2"]:GetAsync(userID) or 0
		
	local QI = Instance.new("IntValue")
	QI.Name = "QI"
	QI.Value = data["QI2"]:GetAsync(userID)or 0
		
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local rep = Instance.new("IntValue")
rep.Name = "Rep"
rep.Value = data["Rep"]:GetAsync(userID) or 1
		rep.Parent = leaderstats
	local Path = Instance.new("StringValue")
	Path.Name = "Path"
	Path.Value = data["Path2"]:GetAsync(userID)or "None"
	
	Stats.Parent = plr
	Layer.Parent = Stats
	Soul.Parent = Stats
TLayer.Parent = Stats
	QI.Parent = Stats
	Path.Parent = Stats
	Items.Parent = Stats



end)
if success then print("Stats in game!")
	
end
	end)

player.PlayerRemoving:connect(function(plr)
	local userId = plr.userId
	local leaderstats = plr:FindFirstChild("leaderstats")
	local Stats = plr:WaitForChild("PStats")
		data["Layer2"]:SetAsync(userId, Stats.Layer.Value)
			data["Soul2"]:SetAsync(userId, Stats.Soul.Value)
				data["QI2"]:SetAsync(userId, Stats.QI.Value) 
						data["Path2"]:SetAsync(userId, Stats.Path.Value)
						data["TLayer2"]:SetAsync(userId, Stats.TLayer.Value)
						  data["Rep"]:SetAsync(userId, leaderstats.Rep.Value)


end)


1 comment

0

update: looking to make and save tables, how would I go about this when I am trying to add something new to the table on a different script? For example; If you have 10 coins you get this sword, then it saves a value into the table

1 answer

I decided to just add boolvalues to data until I figure out what I want to do

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