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

Data not loading?! (It works fine besides it not loading)

Asked by 4 years ago
Edited 4 years ago

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

001local data = require(script.DataModule)
002 
003local DSS = game:GetService("DataStoreService")
004local statSave = DSS:GetDataStore("stats_Test2020")
005local settingSave = DSS:GetDataStore("settings_Test2020")
006local careerSave = DSS:GetDataStore("careers_Test2020")
007 
008--ughh its not working
009 
010game.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)
View all 107 lines...
0
i had trouble like this before and how i solved it was just adding pcalls HappyTimIsHim 652 — 4y
0
it seems like ur making int and boolvalues looping through the saved data. if there's nothing inside then it wouldn't create anything i guess HappyTimIsHim 652 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

01game: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
View all 27 lines...
0
tysm ill try this iiDev_Hunt3r 64 — 4y
0
Its still not working xD iiDev_Hunt3r 64 — 4y
0
Make sure that you did not delete the PlayerRemoving function. Simply keep your original script, but then add this one at the end. AntiWorldliness 868 — 4y
0
It works now xD But datas being throttled iiDev_Hunt3r 64 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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:

1local remote = <remote>
2 
3local data = <value thingy in player>.Value
4 
5local function save()
6    remote:FireServer(data)
7end

Server:

1local remote = <remote>
2 
3remote.OnServerEvent:Connect(function(player, data)
4    Datastore:SetAsync(key, data)
5end)

idk but it works

0
i- i know that xD i am using a remote... iiDev_Hunt3r 64 — 4y
0
The refuses to load/save iiDev_Hunt3r 64 — 4y
0
? i see not a remote kie1605 0 — 4y
0
You dont need a remote for data... you need it to change stats but im trying to load data! Who uses remotes to load data xD iiDev_Hunt3r 64 — 4y

Answer this question