Module returning the same value every time from script, but not command bar?

Hello.

I have a module that when Module:GetBookings() is done it returns a table. The script is doing this once every second, and then printing it for debugging. Each time, it just prints {}, yet when I do the function in the command bar, it gives me the actual table. Here is the code I used:

local module = require(game.ServerScriptService.Modules.BookingModule)

while wait(1) do
   print(module:GetBookings()) -- Prints {}
end

Yet when done from the command bar, it prints the correct table.


(The {} is what was printed from the server). Any help would be appreciated.

Where are you using BookFood in the script?

There is no need to. The function BookFood just adds a value to a table in the BookingModule, and GetBookings returns that table. When I used bookfood, it added a value to the table, but when the script did GetBooking, the table was empty, yet when I do the GetBooking function from the command line it shows the correct table.

I think there is a high chance that the command bar loads the module separately especially since it has a higher security context. Try using BookFood in a separate script that only runs after 5 or 10 seconds of runtime to see if the problem is a result of using the command bar.

Oh, alright. I’ll try that. Thank you.

The command bar runs on a separate VM/environment than scripts and LocalScripts. I had this same issue while trying to use GetSpeakerList with the ChatService; returned an empty table in the command bar but a full table in a regular server script.

2 Likes