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 3 years ago
Edited 3 years ago
local dataStore = game:GetService("DataStoreService"):GetDataStore("DiceomathyData")
local datst = game:GetService("DataStoreService"):GetDataStore("DiceomathyDataPoint")

starterRolls = 0 --This is the starter money
starterPoints = 0


game.Players.PlayerAdded:Connect(function(plr)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    local points = Instance.new("IntValue")
    points.Name = "Points" --Put ur currency name here, mine is Money
    points.Value = dataStore:GetAsync(plr.UserId) or starterPoints
    points.Parent = leaderstats

    local rolls = Instance.new("IntValue")
    rolls.Name = "Rolls" --Put ur currency name here, mine is Money
    rolls.Value = dataStore:GetAsync(plr.UserId) or starterRolls
    rolls.Parent = leaderstats
end)

game.Players.PlayerRemoving:Connect(function(plr)

    dataStore:SetAsync(plr.UserId, plr.leaderstats.Rolls.Value)

end)

game.Players.PlayerRemoving:Connect(function(plr)
    datst:SetAsync(plr.UserId, plr.leaderstats.Points.Value)
end)

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 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 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:

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

Retrieving with a table:

local data = dataStore:GetAsync(plr.UserId)

points.Value = data[1]
rolls.Value = data[2]
0
can you show me the table? the two datastores wont work. Jakob_Cashy 79 — 3y
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 — 3y
0
i updated the code to the two save stores, also not sure where to put these table things. Jakob_Cashy 79 — 3y
Ad

Answer this question