I recently encountered a weird problem with modulescripts,
I have a function within it that grabs a folder from a Player’s data and returns that as a rebuilt table to the script that requested it.
-- ModuleScript
MainFunction.Plr_ListFolderContents = function(Player, Folder)
if Player and Folder ~= nil then
local Data = game.ServerStorage.PlayerData:FindFirstChild(Player, true)
if Data ~= nil then
local DestringFolder = Data:FindFirstChild(Folder, true)
local Final = {}
local Names = DestringFolder:GetDescendants()
for i, v in pairs(Names) do
-- table.insert(Final, v.Name)
if v.ClassName ~= "Folder" then
Final[v.Name] = tostring(v.Value)
else
Final[v.Name] = "FOLDER"
end
end
return Final
else
warn("Player's Folder is nil!", debug.traceback())
end
else
warn("Plr_ListFolderContents has a nil value! Check your Requesting Line!", debug.traceback())
end
end
It does actually return a whole table with the names/values i need, but the index of the table is 0???
this leads to problems where i need to use for loops to iterate through the folder to set them all back to 0…
-- Separate Script
local function ResetData(Player, Data)
print(#Data, Data) -- 0, {...}
for i, v in pairs(Data) do
Main.UpdateStat(Player, tostring(Data[i]), 0)
print("Reset", Data[i]) -- Proof that this does not fire
end
end
-- Skipping for loop??
ResetData(Player2, Main.Plr_ListFolderContents(Player1, "SPTriggers"))
I’ve never seen something like this before, it works fine but this is super specific. Do i have to rebuild the table on the script’s end so that it has the proper index, or just send the index of the Modulescript’s table and iterate from there?
Any help is greatly appreciated.