I Have 40 wins, I Win Again but It Won't Say Up There 41 wins, Stuck To 40 won't go upper

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("winsSaveSystem")--change all "wins" to what value you want and keep doing it 
local Debounce = tick() -- Assign tick() to the variable
game.Players.PlayerAdded:Connect(function(player)
 local folder = Instance.new("Folder", player)
 folder.Name = "leaderstats"
 local wins = Instance.new("IntValue", folder)
 wins.Name = "Wins"
 wins.Value = ds1:GetAsync(player.UserId) or 0
 ds1:SetAsync(player.UserId, wins.Value)

workspace.Lobby.DROPDOWN.Winner.Touched:Connect(function()
    if (tick() - Debounce) >= 5 then -- Make sure 5 seconds have elapsed since last debounce
        Debounce = tick()
            wins.Value = wins.Value + 1


    end
end)



 wins.Changed:Connect(function()
  ds1:SetAsync(player.UserId, wins.Value)
 end)



end)

6 comments

0

Anything in the output?

0

Never save anything on a Changed event. Also, when you save, wrap the SetAsync/UpdateAsync in a pcall.

0

Nothing on Output, By the way how do i wrap SetAsync/UpdateAsync

0

An example of pcall being used would be pcall(ds1.SetAsync, ds1, player.UserId, wins.Value).

0

pcall has two return values, the first one being a boolean that says whether or not a save was successful, and the second one is an error message if the save was unsuccessful. The error message would be nil if the save was a success.

0

You can set two variables to those return values like so: local success, message = pcall(ds1.SetAsync, ds1, player.UserId, wins.Value).