So i’ve been working on a pokemon like battle system for a bit and im stuck on the save system using a module script, spefically how the data is retrieved from the module.
–PlayerDataModule
local PlayerData = {} – Data indexed as Player.UserId
local function newPlayerData()
return {
["Mons"] = {
["Party"] = {
[1] = false,
[2] = false,
[3] = false,
[4] = false,
[5] = false,
[6] = false
},
["Box"] = {
}
},
}
end
function Data.ReturnData(Player, Category, SubCategory) -- ie category = Mons, SubCategory = Party
if Category ~= nil then
if SubCategory ~= nil then
return PlayerData[Player.UserId][Category][SubCategory]
else
return PlayerData[Player.UserId][Category]
end
else
return (PlayerData[Player.UserId])
end
end
so to get the players party i do PlayerDataModule.RetrunData(Player, “Mons”, “Party”).
local PlayerDataModule.RetrunData(Player, “Mons”, “Party”)
The data returns fine however i noticed that it points to the orignal section of data that it is retrieving instead of being a new table. this isnt good as when the script say modifys the health of a mon it points back to the table in the mdoule script and modifys it. So i guess what i want to know is how do i make the function return the table and not a pointer?