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

Saving system switches values of both stats to equal?

Asked by 4 years ago
Edited 4 years ago
01local dataStore = game:GetService("DataStoreService"):GetDataStore("DiceomathyData")
02local datst = game:GetService("DataStoreService"):GetDataStore("DiceomathyDataPoint")
03 
04starterRolls = 0 --This is the starter money
05starterPoints = 0
06 
07 
08game.Players.PlayerAdded:Connect(function(plr)
09 
10    local leaderstats = Instance.new("Folder")
11    leaderstats.Name = "leaderstats"
12    leaderstats.Parent = plr
13 
14    local points = Instance.new("IntValue")
15    points.Name = "Points" --Put ur currency name here, mine is Money
View all 33 lines...

My script seems to be saving the data, but... not properly. When I add the points to let's say, 123, and rolls to 0. Then when I come back the points is now 0 and rolls is 0. I tried again with different values. 100 for points, 10 for rolls, when I rejoined my game, both values were 100. I would like a person out there to figure out how to get both values separately saved.

0
Simple, "points.Value = dataStore" and "rolls.Value = dataStore". Same datastore, change "rolls" to "rolls.Value = datst" 9mze 193 — 4y

1 answer

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

The reason why they are both the same value is that both saved values were saved in the exact same DataStore. When the data is retrieved, it will get the last value saved which in this case is the points. Consider using either 2 different datastores, or use 1 but save a table with the data.

Saving with a table:

1dataStore:SetAsync(plr.UserId, {plr.leaderstats.Points.Value, plr.leaderstats.Rolls.Value})

Retrieving with a table:

1local data = dataStore:GetAsync(plr.UserId)
2 
3points.Value = data[1]
4rolls.Value = data[2]
0
can you show me the table? the two datastores wont work. Jakob_Cashy 79 — 4y
0
Two datastores should work so I don't know why it isn't working for you other than a possible bug in the new code. CreationNation1 459 — 4y
0
i updated the code to the two save stores, also not sure where to put these table things. Jakob_Cashy 79 — 4y
Ad

Answer this question