The data script below works all well but refuses to load. It doesn't show any errors in output! Any idea whats going on? lmk thx
The issue is that the data wont load correctly! pls help
001 | local data = require(script.DataModule) |
002 |
003 | local DSS = game:GetService( "DataStoreService" ) |
004 | local statSave = DSS:GetDataStore( "stats_Test2020" ) |
005 | local settingSave = DSS:GetDataStore( "settings_Test2020" ) |
006 | local careerSave = DSS:GetDataStore( "careers_Test2020" ) |
007 |
008 | --ughh its not working |
009 |
010 | game.Players.PlayerAdded:Connect( function (player) |
011 | local key = "Data-ID" ..player.UserId |
012 |
013 | local statData = statSave:GetAsync(key) |
014 | local settingData = settingSave:GetAsync(key) |
015 | local careerData = careerSave:GetAsync(key) |
I just skimmed through your script, but you said everything was working fine except for the data not saving. I know a lot of people have this problem too. Check out this article. Hopefully this answers your question. Basically, the server may shut down before the last player leaves or if you're playing Solo in the Studio, thus not being able to complete all the functions. To fix that, use BindToClose
. Place the function that you want to run before the server shuts down, inside of the BindToClose
function. The function should be completed less than 30 seconds at most before the server shuts down.
01 | game:BindToClose( function () -- Runs the PlayerRemoving function before server shuts down |
02 | for i, player in pairs (game.Players:GetPlayers()) do |
03 |
04 | local key = "Data-ID" ..player.UserId |
05 | local Stats = player.leaderstats |
06 | local Settings = player.Settings |
07 | local Careers = player.Careers |
08 |
09 | local statsTable = { } |
10 | local settingsTable = { } |
11 | local careersTable = { } |
12 |
13 | for i,v in pairs (Stats:GetChildren()) do |
14 | table.insert(statsTable, v.Value) |
15 | end |
I had this problem for a while and i figured Values inside of player when updated don't update for the server(or something like that idk). the way i worked around this was i had a remote send the data from a local script to the server when it was called.
example...
Client:
1 | local remote = <remote> |
2 |
3 | local data = <value thingy in player>.Value |
4 |
5 | local function save() |
6 | remote:FireServer(data) |
7 | end |
Server:
1 | local remote = <remote> |
2 |
3 | remote.OnServerEvent:Connect( function (player, data) |
4 | Datastore:SetAsync(key, data) |
5 | end ) |
idk but it works