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

Leaderboard saver not working?

so I tried making a save leaderboard script and it didnt work any help?

local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("leaderstats")


game.Players.PlayerAdded:connect(function(player)
	
	local Leaderstats = Instance.new("Folder", player)
	Leaderstats.Name = "leaderstats"
	
	
    local Size = Instance.new("IntValue", Leaderstats)
    Size.Name = "Size"
	Size.Value = 1
	
	
	local Rebirths= Instance.new("IntValue", Leaderstats)
    Rebirths.Name = "Rebirths"
	Rebirths.Value = 0
	
	
	local SizeData, RebirthsData
	
	local success, errormessaage = pcall(function()
SizeData = DataStore:GetAsync("size-"..player.UserId)
RebirthsData = DataStore:GetAsync("rebirths-"..player.UserId)
	end)
	if success then
		if SizeData then
			Size.Value = SizeData
			Rebirths.Value = RebirthsData
		end
	end
	
end)
game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStore:GetAsync("size"..player.UserId,player.leaderstats.Size.Value)
		DataStore:GetAsync("rebirths"..player.UserId,player.leaderstats.Rebirths.Value)
	end)
end)

2 answers

To save, you must use SetAsync, not GetAsync. GetAsync retrieves the data from the datastore.

1 comment

0

Um I am really confused this still wont work.

It's not a game-changer, but, where you put:

local Leaderstats = Instance.new("Folder", player)

It is actually not good practice to set the parent before you set the properties of an item.

I'd suggest doing:

local Leaderstats = Instnace.new('Folder')
Leaderstats.Name = 'leaderstats'
Leaderstats.Parent = player

Secondly, your DataStore isn't saving any data because you are not requesting it to save any data. On line 37 and line 38, you accidentally put GetAsync, instead of SetAsync.

I'm assuming you already know this but GetAsync retrieves saved data not sends it.

I hope this answers your question. Also sorry that I answered a while after you posted it.

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