So I wrote this Module Script, it's purpose is not relevant, but as you can see I declare serverdata
at the top of the Module. Then I go to add an element to it at the end of the module.addBuilding
function. I check the table, everything looks fine. Then, I go to call the module.saveServer
function and it views the serverdata
table as having no values in it.
When in studio, what I said previously happens. While in a real game server, it all works fine. And no there isn't anything that is modifying the data in between when I add it to the table and retrieve it.
I have come across this problem twice now, and I still have no idea why it works in a real game server, but not in studio. It seems like the opposite of what usually ends up happening (works in studio, not in real game server).
local DataStoreService = game:GetService("DataStoreService") local D_Version = 0 local ServerDataStore = DataStoreService:GetDataStore("TestGameData"..D_Version) local Server = "Server::Test0" local seperator = "|" local serverdata = {} local module = {} -- Building Helper: Type|Name|CFrame|Owner|Health module.addBuilding = function(building) local stringElement = "B".. building.Name..seperator.. tostring(building.PrimaryPart.CFrame)..seperator.. tostring(building.Configuration.Owner.Value)..seperator.. tostring(building.BuildingHealth.Health) table.insert(serverdata,stringElement) print(#serverdata) end module.saveServer = function() local data = ServerDataStore:GetAsync(Server) --local newdata = getUpdatedData(serverdata) local newdata = serverdata for i,v in pairs (newdata) do print(v) end if not data then ServerDataStore:SetAsync(Server, newdata) else local function updateValue(oldValue) return newdata end ServerDataStore:UpdateAsync(Server,updateValue) end warn("server data was successfully saved") end return module
DataStore
within ROBLOX Studio, you need to enable Studio API access for the game.To do this:
To anyone who may have this problem with a ModuleScript
not working in Studio, but works in game. I was using the Studio Command Line
to run my ModuleScript
functions. Apparently the Command Line
saves the initial state of the ModuleScript
due to its higher security level across client and server. This makes it so if you make any changes such as add a player to a table or something like that it will not see it since it only has the initial state.
In order to test the ModuleScript in Studio you need to use Scripts
.