So I have 2 values, they are just int values, without leaderstats. Which value i save last via Server Side, the other value is going to be set to that value too.
Eg if i do theCash's value to 100 then I do theWins's Value to 500
When i reload the game, both of them will be 500, why?
local DS = game:GetService("DataStoreService"):GetDataStore("a")
game.Players.PlayerAdded:Connect(function(player)
local theCash = Instance.new("IntValue",player)
theCash.Name = "theCash"
theCash.Value = DS:GetAsync(player.UserId) or 0
local theWins = Instance.new("IntValue", player)
theWins.Name = "theWins"
theWins.Value = DS:GetAsync(player.UserId) or 0
local function saveTheData(theData)
theData.Changed:Connect(function()
DS:SetAsync(player.UserId, theData.Value)
end)
end
saveTheData(theCash)
saveTheData(theWins)
end)

4 comments
Also note, this way you are doing a lot of requests, you will hit the limits, and it will in turn start queueing your setasyncs which could result in dataloss
but if instance.new is bad, why you wrote it in the code too
cuz i just showed you the solution for different keys
https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 read this, it explains why it is bad