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

Reset Stats Button Isn't Working?

Asked by 8 years ago

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)
0
What script types are they, local or server scripts? Also do you get any errors? General_Scripter 425 — 8y
0
Server Scripts, I don't get any errors LifeInDevelopment 364 — 8y
0
Could it be that in the button script you used Player_ and not User_ when saving the data? General_Scripter 425 — 8y
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. General_Scripter 425 — 8y
View all comments (4 more)
0
Ahh good idea LifeInDevelopment 364 — 8y
0
I used .Changed and User_ but its still not saving LifeInDevelopment 364 — 8y
0
Dude... You're not setting the actual values of your leaderstats. Inside the MouseButton1Down function, set the player's stats to 0. TheDeadlyPanther 2460 — 8y
0
^ not working LifeInDevelopment 364 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

"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!')

0
wins.Value = 0 same with credits SirDabbingston 0 — 8y
0
Yeah I changed it to user but it didn't work. LifeInDevelopment 364 — 8y
Ad

Answer this question