Function Not Sending Full Table, Only Happens 40% of The Time?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? My entire Table to send 100% of the time.
  2. What is the issue? My Function will sometimes send a shortened version of my full Table, rather than the full thing. It only happens about 40% of the time, so it’s random.
  3. What solutions have you tried so far? A lot.

This error occurs about 40-50% of the time when starting my Game.
When the issue does occur, the Table equals:

  04:57:51.611   ▼  {
                    ["Question"] = "How much do you enjoy the Gameplay?",
                    ["ResponseType"] = "Rate"
                 }  -  Client - SurveyHandler:38

When the issue doesn’t occur, the Table equals:

  05:00:29.937   ▼  {
                    ["ID"] = 1,
                    ["Question"] = "How much do you enjoy the Gameplay?",
                    ["ResponseType"] = "Rate",
                    ["Survey"] = 1
                 }  -  Client - SurveyHandler:38

So the overall issue is that sometimes the Table is only sent with 2 Values rather than all 4.

Ok, so in my StarterGUI I have a LocalScript, which pulls from a ModuleScript in my ReplicatedStorage.

The ModuleScript in my ReplicatedStorage is meant to be a Config File where I store my Survey Setup, here are a few members of the Table within the file:

local Configuration = {
	{Survey = 1, ID = 1, Question  = "How much do you enjoy the Gameplay?", ResponseType = "Rate"},
	{Survey = 1, ID = 2, Question  = "How likely are you to recommend Santa Simulator to a Friend?", ResponseType = "Rate"},
}

(SurveyConfig Module Script in ReplicatedStorage)

My LocalScript in the StarterGUI requires the SurveyConfig. It uses this, loops through the Table, and each time sends the Config line to a ModuleScript located in the same directory as the LocalScript (StarterGUI).

local surveyConfig = require(ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("Config"):WaitForChild("SurveyConfig"))
local surveyManager = require(script.Parent:WaitForChild("SurveyManager"))

local storedSurvey = 0
for _, configLine in ipairs(surveyConfig) do
	if storedSurvey ~= configLine.Survey then
		print(configLine)
		local surveyTemplate = surveyManager.newSurvey(configLine)
    end
end

(SurveyHandler Local Script in StarterGUI)

My ModuleScript in the same directory as the LocalScript will run the function called.

function Survey.newSurvey(config)
	print(config)
	print(config.Survey)
end

(SurveyManager Module Script in StarterGUI)

The two functions might be running synchronously. meaning that when you fetch the data so as to print it,
it will only get half the table, because only half the table has been made.

If you put a wait(1) to make it wait for a sec at line 37, so it waits before printing the table, does it print the entire table?

Thanks for the suggestion! I tried adding a wait to that section, but unfortunately, it did not make any difference.

	if storedSurvey ~= configLine.Survey then
		wait(5)
		print(configLine)

Is the table being wrote to during runtime or is it a predefined table?

If a table isn’t fully printing in the output, it means some of the keys you want have to been set to nil or not defined.

Check that your table is actually setting these values (if you dont want them to be nil). Maybe by using print statements around your if statements to make sure code is being reached

(Of course I dont have much to go off so I’m making educated guesses)

Code should be deterministic every time it runs (unless you use math.random) which means there’s something going wrong with the Survey object’s creation

The Table is within a ModuleScript inside of ReplicatedStorage. If I understand correctly, it’s a predefined table, because it’s already saved in a file, not created upon start.

1 Like

If the Table is defined with a ModuleScript already as

local Configuration = {
	{Survey = 1, ID = 1, Question  = "How much do you enjoy the Gameplay?", ResponseType = "Rate"},
}

How would I check the Table is setting these Values?

I believe the above-printed Table might be clarifying that the Table is setting SOME values, but not all of them.

repeat task.wait() until #Configuration == 4

Huh, I thought this would actually be the solution! Unfortunately, it seems like the loop will just go on forever when this issue randomly happens.

local storedSurvey = 0
repeat task.wait() print(#surveyConfig) until #surveyConfig > 4
for _, configLine in ipairs(surveyConfig) do
  06:59:55.845  Gifts  -  Client - CurrencyDisplay:13
  06:59:55.846   ▶ 1 (x68)  -  Client - SurveyHandler:51
  06:59:56.978  Coins  -  Client - CurrencyDisplay:13
  06:59:56.979   ▶ 1 (x64)  -  Client - SurveyHandler:51
  06:59:58.044  BattlePass_Level  -  Client - CurrencyDisplay:13
  06:59:58.045   ▶ 1 (x2686)  -  Client

That means that something is for whatever reason removing entries from that table.

Could 2 scripts require it at the same time cause that? I’m really not sure what would be causing entries to be removed because it’s only even called in 2 places.
image

I’ve tried further debugging this issue, but still haven’t found any viable solution. Might anyone have any other ideas?

the values shouldnt change
the only reason you can change it between server scripts, or between local scripts, is because the cached value is changed, not the value in the module

what does the if statement around the print do? maybe that’s triggering sometimes and not on other times?

Are you referring to the following?

If so, this is meant as a way to add multiple Surveys to a GUI, without adding the same Survey twice.

I was referring to the table being changed dynamically in whatever source script it’s pulled from.

maybe it’s related to this? Nonstring indices of a keyed table are converted to strings when sent through a remote - #11 by tnavarts
try making ID and Survey have string values and convert them to strings later

1 Like

Dang, I was really excited when I saw this because I thought the issue and/or a solution might’ve finally been found!

Unfortunately even making all my ID & Surveys have String values, the issue can still occur.

	{Survey = "1", ID = "1", Question  = "How much do you enjoy the Gameplay?", ResponseType = "Rate"},
	{Survey = "1", ID = "2", Question  = "How likely are you to recommend Santa Simulator to a Friend?", ResponseType = "Rate"},

It’s really odd too because it still only gets the last two keys!

                    [1] =  ▼  {
                       ["Question"] = "How much do you enjoy the Gameplay?",
                       ["ResponseType"] = "Rate"
                    }
                 }  -  Client - SurveyHandler:49
  02:21:49.579   ▶ 1 (x117)  -  Client - SurveyHandler:51

I still haven’t discovered the reasoning behind the issue, but I did find a hopefully only temporary fix, which was to just add the Table directly to the File, rather than calling it from the ModuleScript.

in the module, is it doing any operations besides return configuration?