Data saving problems

So for my game I’ve been using this DataStore module script I found and it’s been working but now I’ve been having some problems with saving some values, notably a string value.

This is my module for saving player data

I have a pretty similar module albeit slightly different for saving player sword data just to not overload my player datastore since I have like 10 values already being updated there

And then I have my leaderstats script which handles running the loaddata and savadata for both of these modules
image

And I tend to get this error whenever I leave the game and rejoin it, likely because it’s not saving it correctly or because it’s not loading it correctly.

I’m contemplating just switching from Data Stores to ProfileService or something since how finicky this is but since this is just a test game that I don’t plan on updating I don’t really want to go through all the effort of switching the modules since #1 I have no idea how to use profileservice and #2 everything I’ve made is already based around how this is organized.

3 Likes

You might have old player data saved in the datastore which is just {}, even in studio it saves

yea but I’ve been switching the key a bunch to test and it still happens

Add more debugging by printing out Data (example) and identify the core issue.

yea it just has a nil Current Sword value and because it’s nil it prevents any other data from loading so everything is set to 0 or false
image

Consider checking if it exists before setting it like this:

local dataToSet = data[value.Name]
if dataToSet then
	value.Value = dataToSet
end

Also I would recommend you switch over to Profileservice as it is a great module for datastore management

Yea profileservice is better but since I already set everything to be based around data stores I feel like it would take ages and a lot of modifying scripts to swap over.

It doesn’t take long at all, if this game is still not released I definetly recommend you switch over to ProfileService, it will make managing way easier.

would ProfileService or ProfileStore be better since I know ProfileStore is based around service

I believe they are made by the same creator. It is up to you to prefer which one to use.

Alright well I’ll read up on the documentation and try to see if I can swap it around. This will hurt. I’ll just mark your suggestion as the solution.


So I’ve mainly reconfigured my scripts for this module, but when trying to do my nametags again that display some leaderstats values it returns an error saying it can’t find leaderstats in Players.PlayerName. I imagine it’s because the profile hasn’t loaded in yet but I can’t figure out how to make it wait.