Hi, I'm using data stores for my leaderboards and I wanted to add a reset stats button but for some reason it resets the stats and then when I rejoin it comes back to what it was before I reset it. These are all server scripts and errors don't come up on to output.
Here's the Reset Script :
local dataStore = game:GetService('DataStoreService')
local winsData = dataStore:GetDataStore('Wins')
local buxData = dataStore:GetDataStore('Mini-BUX')
local sp = script.Parent
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local wins = player.leaderstats:FindFirstChild('Wins')
local credits = player.leaderstats:FindFirstChild('Mini-BUX')
sp.MouseButton1Down:connect(function()
local key = player.UserId
wins.Value = 0
winsData:SetAsync('User_' .. key .. ':Wins' , wins.Value)
credits.Value = 0
buxData:SetAsync('User_' .. key .. ':Mini-BUX' , credits.Value)
print('Stats Deleted!')
end)
Here's the Leaderboard Script :
local data = game:GetService('DataStoreService')
local buxData = data:GetDataStore('Mini-BUX')
local winsData = data:GetDataStore('Wins')
game.Players.PlayerAdded:connect(function(player)
-- Stats
local leaderstats = Instance.new('Model')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
wins = Instance.new('IntValue')
wins.Name = 'Wins'
wins.Value = 0
wins.Parent = leaderstats
credits = Instance.new('IntValue')
credits.Name = 'Mini-BUX'
credits.Value = 0
credits.Parent = leaderstats
-- Get Stats
local buxStats = buxData:GetAsync('User_'..player.UserId) or 0
local winsStats = winsData:GetAsync('User_'..player.UserId) or 0
credits.Value = buxStats
wins.Value = winsStats
print('Loaded '.. tostring(player.Name).. "'s" .. ' Stats')
end)
game.Players.PlayerRemoving:connect(function(player)
winsData:SetAsync('User_'..player.UserId .. ':Wins', wins.Value)
buxData:SetAsync('User_'..player.UserId .. ':Mini-BUX', credits.Value)
end)

8 comments
What script types are they, local or server scripts? Also do you get any errors?
Server Scripts, I don't get any errors
Could it be that in the button script you used Player_ and not User_ when saving the data?
Also, PlayerRemoving won't always save the data in time, to avoid this use the .Changed function and save it every time the value is changed.
Ahh good idea
I used .Changed and User_ but its still not saving
Dude... You're not setting the actual values of your leaderstats. Inside the MouseButton1Down function, set the player's stats to 0.
^ not working