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

Why are the values in leaderstats the same?

Hi, so I was making leaderstats and when I tried out my game in Roblox(not Roblox Studio), I sold my items so my Money increased. But when I went back into Roblox Studio, my Money and Stored value becomes the same, is there any fix for this? I have tried to solve it many times but it didn't work. Any help is appreciated!

Here's the code:

local dataStore = game:GetService("DataStoreService"):GetDataStore("MoneyData")

starterMoney = 0

game.Players.PlayerAdded:Connect(function(plr)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = dataStore:GetAsync(plr.UserId) or starterMoney
	money.Parent = leaderstats
	
	local money = Instance.new("IntValue")
	money.Name = "Stored"
	money.Value = dataStore:GetAsync(plr.UserId) or starterMoney
	money.Parent = leaderstats
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	dataStore:SetAsync(plr.UserId, plr.leaderstats.Money.Value, plr.leaderstats.Stored.Value)
	
end)

4 comments

0

Just change the name for reference, e.g replace money with money2, so both values are unique. There's a possibility that when saving it referenced both values since they both are identical.

0

Ok thanks for your help!

0

Oh wait I don't think thats the issue. When you went back into studio, did your values change to 0?

0

No, but it still has the same issue

1 answer

✓ Accepted answer

both values are saving into 1 data store named "MoneyData" for saving "Stored" value you will need a new data store named "MoneyData2" or something

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