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

How do I add a value to a DataStore without overwriting it?

Asked by 3 years ago

So, I was making some minigames, it was all perfect until something showed up. The Data Store saves how many wins a player had and kept the data the same when the player rejoined, but the new win overwrote all the previous ones. e.g. if someone had 10 wins, instead of doing +1 win it would make it 1 win. I put the script inside a part that marks the end for an obby. Here it is:

active = false
game.Workspace.LavaRise.Event:Connect(function(h)
    active = false
    script.Parent.Touched:Connect(function(hit)
        wait(.1)
        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
            if not active then
                active = true
                hit.Parent.HumanoidRootPart.Position = game.Workspace.SpawnLocation.Position
                wait(1)
                game.Players[hit.Parent.Name].leaderstats.Wins.Value += 1
                wait(1)
            end
        end
    end)
end)

No error code seems to show up. What do I do?

0
Edit: The wins go up when you're still in the server, but when you leave, it shows however wins you had previously at first, but then it gets overwritten. Valkyrie1277 28 — 3y

Answer this question