I need help saving two types of Instance.new() values, one StringValue, and the other an IntValue, these values get made when a proximity prompt is triggered (for a player collecting an item) and get parented to a folder in the player named ‘CollectedItems’, the IntValue is the items worth/sell value for when the player goes to sell their items, and the StringValue is just the item name, what I want to do is save these instances and their values and load them so that they get created and parented to the ‘CollectedItems’ folder when the player loads the game.
NO ITEMS COLLECTED:
ITEMS COLLECTED: (i want this to show when players data loads)
I’ve lookws for solutions and I tried in pairs loops to loop through the ‘CollectedItems’ folders descendants and then adding them to the data table but it didn’t work. (DATA TABLE BELOW)
SAVE DATA FUNCTION
local data = {
money = ls.Money.Value;
gems = ls.Gems.Value;
equippedBag = inv.EquippedBag.Value;
itemsInBag = #inv.CollectedItems:GetChildren();
totalItemsValue = inv.EquippedBag.TotalItemsValue.Value;
equippedDetector = inv.EquippedDetector.Value;
}
local success, message = pcall(function()
datastore:SetAsync(plr.UserId, data)
end)
LOAD DATA
local data
local success, message = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
if success then
print("Data Loaded!")
money.Value = data.money
gems.Value = data.gems
equippedBag.Value = data.equippedBag
itemsInBag.Value = data.itemsInBag
totalItemsValue.Value = data.totalItemsValue
equippedDetector.Value = data.equippedDetector
else
print("Failed To Load Data.")
repeat task.wait() until datastore:GetAsync(plr.UserId)
data = datastore:GetAsync(plr.UserId)
end