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

5 comments
That is not why it's not working, it is already enabled.
Alright. I'll see if I can figure it out.
I get that it is enabled, you are opening it from the site though right? opening a local version from your computer may not be connected to the datastore's information
Yes from the site, everything in your answer post is what I already have going.
If it works in a real server, but not in Studio, and all that is as I said, I cannot imagine what it could be besides a bug. Standby for anyone else who may have more knowledge than me on this. I am able to access my DataStores within my Studio, and I do not see anything inherently wrong with your code.