Giter Club home page Giter Club logo

Comments (9)

Kampfkarren avatar Kampfkarren commented on July 30, 2024

Can you try this and see what happens (best if it works on a slightly modified baseplate):

  • Join server
  • Change data in some way so that it actually saves
  • Shut down all servers
  • Quickly join back
  • Observe your data is the old data
  • Do NOT change your data
  • Leave, it won't save if data isn't changed
  • Join back later

What data do you get? Old data or the data from when you shut down? My theory is it's still saving by the time people rejoin.

from roblox.

Intrance1 avatar Intrance1 commented on July 30, 2024

I followed the steps and got the old data.

from roblox.

Kampfkarren avatar Kampfkarren commented on July 30, 2024

@Intrance1 That's strange--and it says in the console it didn't save because of unchanged data, correct? DataStore2 runs code on BindToClose, so there could be something incorrect there.

from roblox.

Intrance1 avatar Intrance1 commented on July 30, 2024

There's nothing in the log after the game is shutdown. I'm not sure if messages continue to be posted to the console after the server is shutdown. The message could be posted after I'm kicked from the server and that could be why I don't see anything in the console.

from roblox.

Kampfkarren avatar Kampfkarren commented on July 30, 2024

Can you see what happens when you add this somewhere in your code:

game:BindToClose(function()
    dataStore:Save()
end)

I wonder if it's a BindToClose problem or a DataStore2 problem.

from roblox.

Intrance1 avatar Intrance1 commented on July 30, 2024

That worked. I shutdown the server and "saved key" outputted in the console, then rejoined and had the correct data.

from roblox.

Kampfkarren avatar Kampfkarren commented on July 30, 2024

Strange, that means it must be an issue with how DataStore2 specifically implements it. Not so coincidentally, there's also no unit tests for it.

Here's the relevant lines:

Roblox/DataStore2/init.lua

Lines 619 to 644 in 56a0d27

local event, fired = Instance.new("BindableEvent"), false
game:BindToClose(function()
if not fired then
event.Event:wait()
end
local value = dataStore:Get(nil, true)
for _, bindToClose in pairs(dataStore.bindToClose) do
bindToClose(player, value)
end
end)
local playerLeavingConnection
playerLeavingConnection = player.AncestryChanged:Connect(function()
if player:IsDescendantOf(game) then return end
playerLeavingConnection:Disconnect()
dataStore:Save()
event:Fire()
fired = true
delay(40, function() --Give a long delay for people who haven't figured out the cache :^(
DataStoreCache[player] = nil
end)
end)

It's a bit weird, but the gist of it is:

  • When the player leaves (ancestry changed and they're no longer in the data model), set a "fired" flag to true after it has been saved and fire an event.
  • On BindToClose, if the player hasn't successfully saved yet (the "fired" flag), wait for them to save.

This logic makes sense to me, so I'm not sure why it isn't working. While we could just call :Save() twice, this would fire two requests to save the data, which would add additional overhead.

from roblox.

Intrance1 avatar Intrance1 commented on July 30, 2024

So I was doing some testing with the playerLeavingConnection and I think the problem is with the AncestryChanged event. I replaced it with a PlayerRemoving event and that worked.

from roblox.

Kampfkarren avatar Kampfkarren commented on July 30, 2024

That must be it, the AncestryChanged patch is recent: 620688e

Thanks for you research! I'll fix it when I can unless you want to make a stab at a PR (that also fixes the memory leak the previous version had).

from roblox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.