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

Reset Stats Button Isn't Working?

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

0

What script types are they, local or server scripts? Also do you get any errors?

0

Server Scripts, I don't get any errors

0

Could it be that in the button script you used Player_ and not User_ when saving the data?

0

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.

0

Ahh good idea

0

I used .Changed and User_ but its still not saving

0

Dude... You're not setting the actual values of your leaderstats. Inside the MouseButton1Down function, set the player's stats to 0.

0

^ not working

1 answer

"winsData:SetAsync('Player_' .. key .. ':Wins' , wins.Value) 16 credits.Value = nil 17 buxData:SetAsync('Player_' .. key .. ':Mini-BUX' , credits.Value) 18 print('Stats Deleted!') "

Should be

winsData:SetAsync('User_' .. key .. ':Wins' , wins.Value) 16 credits.Value = nil 17 buxData:SetAsync('User_' .. key .. ':Mini-BUX' , credits.Value) 18 print('Stats Deleted!')

2 comments

0

wins.Value = 0 same with credits

0

Yeah I changed it to user but it didn't work.

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