Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone explain why this Module Script works in a real server, but not Studio?

Asked by 5 years ago
Edited 5 years ago

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

2 answers

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
5 years ago

In order to access a DataStore within ROBLOX Studio, you need to enable Studio API access for the game.

To do this:

  • Go to the "Create" tab on ROBLOX
  • Click on the Gear Symbol
  • Click "Configure Game"
  • Check the box that says "Enable Studio Access to API Services:"
  • Open the game for editing from the website (not from your computer)
0
That is not why it's not working, it is already enabled. climethestair 1663 — 5y
0
Alright. I'll see if I can figure it out. amanda 1059 — 5y
0
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 amanda 1059 — 5y
0
Yes from the site, everything in your answer post is what I already have going. climethestair 1663 — 5y
0
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. amanda 1059 — 5y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Answer this question