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

DataStore not saving data correctly?

Asked by 4 years ago

I've been trying to create a random name generator for all players whenever they firstly join the game, then save it through DataStore. However, each times I play the game I will just get a new name EVEN if the output says (4 times lol) the data has been saved. Help?

01local DataStoreService = game:GetService("DataStoreService")
02local dataStore = DataStoreService:GetDataStore("MyDataStore")
03 
04local function saveData(player)
05 
06    local tableToSave = {
07        player.Character:WaitForChild("Values").Name.Value;
08        player.Character:WaitForChild("Values").Surname.Value
09    }
10 
11    local success, err = pcall(function()
12        dataStore:SetAsync(player.UserId, tableToSave)
13    end)
14 
15    if success then
View all 76 lines...

2 answers

Log in to vote
1
Answered by 4 years ago

This should fix the error you're having, let me know if there are still any errors.

01local DataStoreService = game:GetService("DataStoreService")
02local dataStore = DataStoreService:GetDataStore("MyDataStore3")
03local players = 0
04 
05game.Players.PlayerAdded:Connect(function(player)
06 
07    players = players + 1
08    local key = "Player_"..player.UserId
09 
10    local data
11    local success, err = pcall(function()
12 
13        data = dataStore:GetAsync(key)
14 
15    end)
View all 69 lines...
0
It does! Thank you a lot. <3 (no homo) Fixer1987 95 — 4y
0
If I want to change my name, do I just use the server output to modify the name value in my character? Fixer1987 95 — 4y
0
Yes, you could do it via remote-events, and if you want to reset stats just do this. dataStore:RemoveAsync(key) incurszio 70 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

There is nothing wrong with this script. It is the script of how you set those values

0
There is no script that sets those values, as I aforementioned the values are all set in the script and require no other script. Fixer1987 95 — 4y
0
There is no script that sets those values, as I aforementioned the values are all set in the script and require no other script. Fixer1987 95 — 4y

Answer this question