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

How would I save a specific Leaderstat value via DataStore?

local PlayerJoined_DataStore =
game:GetService('DataStoreService'):GetDataStore('JoinedTimes')

game.Players.PlayerAdded:connect(function(Player)
	local Joined =
	PlayerJoined_DataStore:GetAsync(tostring(Player.UserId))
	local Stats = Instance.new('Folder',Player)
	Stats.Name = 'leaderstats'
	local JoinStat = Instance.new('NumberValue',Stats)
	JoinStat.Name = 'Joined'
	
if Joined ~= nil or Joined == 0 then
	JoinStat.Value = Joined
	print("Loaded stats for "..Player.Name)
	PlayerJoined_DataStore:SetAsync(tostring(Player.UserId), Joined + 1)
	--[[ I would like to GetAsync data for the player kill value.

	I have already made a leaderboard script with the value I want to save,
	the directory of the value I want to save is game.Players.PLRNAME.leaderstats.Kills.Value
	--]]
else
		PlayerJoined_DataStore:SetAsync(tonumber(Player.UserId), 1)
		warn("Failed to load stats for"..Player.Name)
	end
end)

Ignore the "local VALUE =" with an empty definition of the line, look below the line to see what I defined the VALUE to be.

1 answer

I would imagine that all you need to do is create a new data store:

local kills_ds = game:GetService('DataStoreService'):GetDataStore('Kills')
game.Players.PlayerRemoving:Connect(function(player)
    kills_ds:SetAsync(player.UserId,player.leaderstats.Kills.Value)
end

6 comments

0

I will attempt this method, thanks for the submission!

0

My goal of my comment was to GetAsync, if I were to SetAsync in a different line (such as PlayerRemoved), then can I change the "SetAsync" for the loading portion to "GetAsync"?

0

Not sure I follow. Send me a message @BlueGrovyle#5735 on Discord.

0

Method does not work, thanks for the effort.

0

I solved the issue myself, thanks for your time!

0

No problem!

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