#Data sometimes does not save even though there are no errors

34 messages · Page 1 of 1 (latest)

elfin harness
#

So i have a problem where my datastores sometimes doesnt load anything even though there are no errors, but then when i test again at another time it loads everything back. Are datastores outdated? If so, does anyone know a better way to save data

elfin harness
#

Some have for loops some dont

native wren
#

So here’s a example

#

so its like thislua local DataStore = game:GetService('DataStoreService'):GetDataStore('Value') function PlayerAdding(player) local ls = Instance.new('Folder',player) ls.Name = 'leaderstats' local Cash = Instance.new('NumberValue',ls) Cash.Name = 'Cash' local Stage = Instance.new('NumberValue',ls) Stage.Name = 'Stage' local TpStage = Instance.new('NumberValue',ls) TpStage.Name = 'TeleportStage' local Saving = DataStore:GetAsync(player.UserId) for i,v in pairs(ls:GetChildren()) do v.Value = Saving[v.Name] end end function UpdateData(player) local Saving = {} local ls = player:FindFirstChild('leaderstats') for i,v in pairs(ls:GetChildren()) do Saving[v.Name] = v.Value end return Saving end function PlayerRemoving(player) local Update = UpdateData(player) DataStore:SetAsync(player.UserId,Update) end local Player = game.Players Player.PlayerAdded:Connect(function(player) PlayerAdding(player) end) Player.PlayerRemoving:Connect(function(player) PlayerRemoving(player) end)

native wren
elfin harness
#

ill try and review my code

native wren
#

Was it from a texbutton that increases the stats

#

And I forgot u don’t need a pcal

twilit coral
#

does it say in the console that you're fetching from the datastore too often? sometimes it doesnt fulfill datarequest Get/SetAsync calls because they're called too quickly within other calls

elfin harness
#

there are no errors and i made sure the auto save doesnt save too early when the player doesnt have any values in the leaderstats

native wren
#

For me it never goes away

elfin harness
native wren
#

Also use a game bind to close to help it increases a chance to save if player didn’t leave on accident

native wren
#

So what does the one u have look like

elfin harness
#

hold on

twilit coral
#

not to take away from the main point of the thread but what do you mean by a game bind? like the players.PlayerRemoving event?

elfin harness
#

the convert to string is to make the Tools in the inventory into stringvalues so i can save it into the datastore

native wren
#

Ye sometimes StringValue does that

elfin harness
#

?

native wren
#

Some times for me stringvalue doesn’t save for me also

elfin harness
#

oh

elfin harness
#

im just saving the value of the strings and its working fine

#

but sometimes it doesnt load the entire data store

native wren
# elfin harness

Try the example of what I did but write it so it can look good