If I am in studio, I get the error above in the title and then when I press ok, It takes really long to load so I have to close studio. The script getting destroyed is the Datastore2 main module. I tried this to fix it:
local datastore2 = {1936396537}
local function req()
if run:IsStudio()then
warn("You are in Studio")
datastore2[1] = game.ServerScriptService.MainModule
else
datastore2[1] = 1936396537
end
end
req()
local DataStore2 = require(datastore2[1])
The reason I had to make sure studio requires the script is because, with the asset id, it takes time to download in studio. The problem is that the script sometimes does and does not get destroyed at the end when the server closes. In-studio, it says that the data got saved but if the script gets destroyed it does not. The method I tried works where it requires the correct thing but the script still gets destroyed as it is in the game and the data sometimes in a normal game does not save. How do I fix this?
A fix would be to use game:Bindtoclose but how do I make the datastore2 save.