You can write your topic however you want, but you need to answer these questions:
What I want To Achieve stoping the duplication of folders and values
What is the issue? Folders and stats are duplicating over and over again
solutions I’ve tried: Honestly none I’m new to datastore2 and I have no clue why it’s duplicating like this
local datastore2 = require(1936396537)
local function setupUserData()
local userData = {
abilities = {
["Ability1"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability2"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability3"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability4"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability5"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability6"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability7"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability8"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability9"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability10"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability11"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability12"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability13"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability14"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability15"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability16"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability17"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability18"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability19"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability20"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability21"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability22"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability23"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability24"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability25"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability26"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability27"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
["Ability28"] = {
["Ability"] = "";
["Magic Control"] = 0;
["Magic Proficiency"] =0;
};
};
characterStats = {
["Sugars"] = 4;
["Sodium"] = 0;
["Cholesterol"] = 0;
["Carbohydrates"] = 0;
["Iron"] = 0;
["Fat"] = 0;
["Calories"] = 0;
["Height"] = 0;
["Weight"] = 0;
["Protein"] = 0;
};
baseStats = {
["Damage"] = 0;
["MaxDamage"] = 0;
["WalkSpeed"] = 0;
["BaseWalkSpeed"] = 0;
["RunSpeed"] = 0;
["BaseRunSpeed"] = 0;
["Name"] = "";
["Kingdom"] = "";
["Clover"] = "";
["Mana"] = "";
["LastName"] = "";
["Royalty"] = false;
["Nobility"] = false;
["Mana-Zone"] = false;
["Race"] = "";
["Rolled"] = false;
};
}
return userData
end
game.Players.PlayerAdded:Connect(function(player)
game.Players.ChildAdded:Connect(function(player)
local test = Instance.new("Folder",player)
test.Name = "Test"
local userData = datastore2("UserDataStore",player):Get(setupUserData())
datastore2("UserDataStore",player):Set(userData)
local stats = Instance.new("Folder",player)
stats.Name = "stats"
local Sugars = Instance.new("IntValue",stats)
local Rolled = Instance.new("BoolValue",stats)
Rolled.Name = "Rolled"
Sugars.Name = "Sugars"
local Sodium = Instance.new("IntValue",stats)
Sodium.Name = "Sodium"
local Cholesterol = Instance.new("IntValue",stats)
Cholesterol.Name = "Cholesterol"
local Carbohydrates = Instance.new("IntValue",stats)
Carbohydrates.Name = "Carbohydrates"
local Iron = Instance.new("IntValue",stats)
Iron.Name = "Iron"
local Fat = Instance.new("IntValue",stats)
Fat.Name = "Fat"
local Calories = Instance.new("IntValue",stats)
Calories.Name = "Calories"
local Height = Instance.new("IntValue",stats)
Height.Name = "Height"
local Weight = Instance.new("IntValue",stats)
Weight.Name = "Weight"
local Pname = Instance.new("StringValue",stats)
Pname.Name = "Pname"
print(userData["characterStats"]["Sugars"])
stats["Pname"].Changed:Connect(function()
userData["baseStats"]["Name"] = Pname.Value
end)
stats["Rolled"].Changed:Connect(function()
userData["baseStats"]["Rolled"] = Rolled.Value
end)
local function pointsUpdate(UpdatedStats)
Sugars.Value = datastore2("UserDataStore",player):Get(UpdatedStats)["characterStats"]["Sugars"]
Rolled.Value = datastore2("UserDataStore",player):Get(UpdatedStats)["baseStats"]["Rolled"]
print(Rolled.Value)
end
pointsUpdate(userData)
datastore2("UserDataStore",player):OnUpdate(pointsUpdate)
end)
end)