I am currently trying to save a folder with all the models and values using this function:
function Scan(Fold)
local function ScanFolder(Folder, Array)
for _,Child in pairs(Folder:GetChildren()) do
if Child:IsA("Folder") then
Array[Child.Name] = {}
ScanFolder(Child,Array[Child.Name])
elseif Child:IsA("Model") then
Array[Child.Name] = {}
ScanFolder(Child,Array[Child.Name])
elseif Child:IsA("ValueBase") then
Array[Child.Name] = Child.Value
end
end
return Array
end
local Array = ScanFolder(Fold, {})
return Array
end
But for some reason, when it is scanning, if there are two or more models, it will only scan the first model. I tested it with some random folder with models, but it gives the same result
It is supposed to go through all the folders and models and extract their values inside them. But it only saves on model if there is more than one in a folder.
You can check if your table already has an object named that and then concat a string after it like (1). Or if you want to rely on this system, just don’t have models with same names.
The problem is that I am using it to save part of a placement system, so many of the models will have the same name. I will concatenate them with numbers i guess
No problem and if you want to be safe you can check if a model named that is already present on the same parent with another part. It’s as easy as
if model:FindFirstChild(generatedGUID) then generatedGUID = HttpService:GenerateGUID() end
Your script only checks for parents so chances of this happening is even more little. And if you want to be 100% safe you can do a repeat function which’ll generate a new GUID until it’s not found if you are planning for players to have massive building areas. However this really isn’t needed because chances of this happening twice is probably same with same person winning the grand prize on a lottery twice with 2 tickets.
One more thing (sorry about this) But how would I retrieve the original value after the data has been loaded in? When I load in the data now, it will be something like “ItemName1298736249378492102hben1jh2jdbax” or whatever. Normally, I would use string.gsub if the extra string was set. But now I am not sure how to get the single name.
GUID’s start with { if I’m not wrong so you can just string.split it with { character. If they don’t start with it you can put the ID between {} these.