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

SetAsync isn't saving [Added More Scripts]?

For some reason this doesn't save.

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
	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)

MainScript :

-- Changes Stats
				player.leaderstats['Mini-BUX'].Value = player.leaderstats['Mini-BUX'].Value + 100
				buxData:SetAsync('User_' ..player.UserId .. ':Mini-BUX', player.leaderstats['Mini-BUX'].Value)
				
				player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
				winsData:SetAsync('User_'..player.UserId .. ':Wins', player.leaderstats.Wins.Value)

3 comments

0

Can we see more of the code?

0

There's not enough to reach a conclusion. Are you sure your loading isn't wrong?

0

I have updated the script.

1 answer

✓ Accepted answer

You need to set the value of the leaderstat values to your GetAsync data, so:

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

    local wins = Instance.new('IntValue')
    wins.Name = 'Wins'
    wins.Value = 0
    wins.Parent = leaderstats

    local 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', player['leaderstats'].Wins.Value)
    buxData:SetAsync('User_'..player.UserId .. ':Mini-BUX', player['leaderstats']['Mini-BUX'].Value)
end)

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