I am creating a tycoon kit (yes, I know) and I am trying to add memory for what buttons the player has pressed in their tycoon. At the moment, I have a MemoryModule which works like so:
local Module = {}
local ButtonMemory = {}
local ButtonsFolder = script.ButtonsFolderReference.Value
---------------------------------------------------------
-- Note about ButtonMemory: Order Matters --
-- Keep this in mind when using or modifying the array --
---------------------------------------------------------
-- Adds a button id to the memory
Module.AddButtonMemory = function(id)
ButtonMemory[#ButtonMemory + 1] = id
end
-- Sets all the button ids
Module.SetButtonMemory = function(tbl)
ButtonMemory = tbl
end
-- Returns all button ids in the memory
Module.GetButtonMemory = function()
return ButtonMemory
end
-- Takes all the memory for this tycoon and applies it as nessecary
Module.ApplyMemory = function(Player)
-- Apply button memory
local Buttons = ButtonsFolder:Clone():GetChildren()
for i,bid in ipairs(ButtonMemory) do
for j,v in ipairs(Buttons) do
if (v.Value.Configuration.Id.Value == bid) then
require(script.ButtonModuleReference.Value)(Player, v.Value, true)
table.remove(Buttons, j)
end
end
end
end
return Module
Basically, when a button is pressed it will call Module.AddButtonMemory with the ID of the button that was pressed. This will add the button to the end of the table which will end up saving both the ID of the button and the order in which the button was pressed as compared to the previous buttons. This is what I need to be saved.
Eventually, our DataStore managing script will come along to require this script and call Module.GetButtonMemory. It works like so:
Module.Save = function(Player, Attempts)
-- ...
local MemoryModule = require(Tycoon.Scripts.MemoryModule)
local DataButtons = MemoryModule.GetButtonMemory()
-- ...
end
(The SetMemory function is only called when loading save data the second they claim the tycoon and works properly)
The issue comes into play when we get the memory. For some reason, the DataButtons is completely empty!
I’ve added print statements in the AddMemory function, the DataStore manager, and the ButtonScript that adds the button id. Everything works properly (that is, the buttons are stored in the memory) all the way up until the DataStore manager attempts to call GetButtonMemory. The table is completely blank!
All of the related scripts are server scripts and/or module scripts, so they should be running on the server.
Here is a video describing the functionality and the issue: 2021 04 12 21 54 42 - YouTube
Any ideas what could be causing the issue? Let me know if you need more information!
EDIT: I have found that this issue only occurs when running the following line of code ON THE SERVER in Studio’s console:
require(game.ServerScriptService.DataManager).Save(game.Players.FireController1847)
It works fine when the internal DataManager calls the save function. I have no idea why this could be the case.