March 20, 2021, 5:41am
Datastore Not Storing Info
I’ve created a datastore to save the time it took a player to complete a level. The datastore has failed to save anything after multiple attempts.
I’ve tried multiple solutions like changing the names of things which didn’t have much effect on anything.
The script is server sided and it is located in the ServerScriptService
Here is the script:
PB = game:GetService("DataStoreService"):GetDataStore("PB")
repeat wait(1) until player.Character
local TimeTrial = Instance.new("Folder")
TimeTrial.Name = "TimeTrial"
TimeTrial.Parent = player
local PersonalBest = Instance.new("StringValue")
PersonalBest.Name = "PersonalBest"
PersonalBest.Parent = TimeTrial
PersonalBest.Value = "0.00"
if PB:GetAsync("Points_"..player.Name) ~= nil then
PersonalBest.Value = PB:GetAsync("Points_"..player.Name)
PersonalBest.Value = '0.00'
Thanks a lot if you could help <3
Couple things unrelated:
You should only save data every 60 seconds or so and upon the player leaving.
You get the datastore 2 times when you could just get it once.
Always use userid for datastores.
Is the function for setAsync actually running?
March 20, 2021, 5:46am
It’ll only save whenever
PersonalBest changes from it’s value. Also save data via the user id, not the name since if the player changes their name, you’ll end up loading up a new data for them.
March 20, 2021, 5:48am
I figured to use UserId rather than the player names. I have so when the player reaches the end of the level it changes the value of PersonalBest. It just won’t save to the datastore.
Thanks for the help btw
I just noticed that you used
.Changed. The variable passed to the connected function is the name of the property changed, not the value.
edit: nvm, that doesn’t apply to values
March 20, 2021, 5:53am
Are you sure that
PersonalBest is changed?
No, for string values, it is the new value.
March 20, 2021, 5:55am
I’ve actually have realized that this script was saving the data locally. Thanks for the help though… I’m so sorry