Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Saving system switches values of both stats to equal?

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.

1 comment

0

Simple, "points.Value = dataStore" and "rolls.Value = dataStore". Same datastore, change "rolls" to "rolls.Value = datst"

1 answer

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]

3 comments

0

can you show me the table? the two datastores wont work.

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.

0

i updated the code to the two save stores, also not sure where to put these table things.

This discussion is preserved as it was. New answers, comments, and votes are closed.