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

Why are the values in leaderstats the same?

Asked by 4 years ago

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)
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. Xx_FROSTBITExX 116 — 4y
0
Ok thanks for your help! SUPERMEGADANTHEMAN 33 — 4y
0
Oh wait I don't think thats the issue. When you went back into studio, did your values change to 0? Xx_FROSTBITExX 116 — 4y
0
No, but it still has the same issue SUPERMEGADANTHEMAN 33 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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

Ad

Answer this question