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

How can I keep leaderboard stats in different places?

I have different ROBLOX places connected through one game, and I would like to know how to keep the leaderboard stats of players in the different games.

Thank you.

1 answer

As long as you already have a leaderboard script that sets up the leaderboard in each game, this will carry the leaderboard data to each one. So just make sure that each place has a 1- a leaderboard script, 2- this script. Tell me if you have any problems.

--[[Savin'
		Dem
			Stats	
--]]
game.Players.PlayerRemoving:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i =  1, #statstorage do
	datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
	print("saved data number "..i)
	
end
print("Stats successfully saved")	
end)


--[[
	Loadin'
		Dem
			Stats
--]]
game.Players.PlayerAdded:connect(function(player)
		local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
	
	player:WaitForChild("leaderstats")
	wait(1)
	local stats = player:FindFirstChild("leaderstats"):GetChildren()
	for i = 1, #stats do			
	stats[i].Value = datastore:GetAsync(stats[i].Name)
	print("stat numba "..i.." has been found")
		end
end)

2 comments

0

May I ask what the "1-" and "2-" represent? I'm very new to advanced scripting, very sorry if this sounds "newbie."

0

This didn't work.. any suggestions?

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