If I make a custom leaderboard should I still use leaderstats to propegate the data to all cleints?

I’ll be hiding the built in roblox leaderstats UI as described here:

My questions is, should I still use the leaderstats system as described above because it somehow auto propagates scores to all connected cleints?

Or do I need to create my own propagation system either way?

Thanks!

It is your choice as it is a custom leaderboard, I recommend using the leaderstats system the default leaderboard uses in the event you choose to go back.

1 Like

If you meant that it changes across all clients, then yes, you would have to make your own system, but Roblox does that already with their leaderboard.

1 Like

Ah.

Something very fundamental about the Roblox server/client paradigm that I didn’t get is that ALL player data set on the server is automatically propagated to each client.

So, if you do something like this on the server:

	local players = game:GetService("Players")
	players.PlayerAdded:Connect(function(player)

	    local myFolderInstance = Instance.new("Folder")
	    myFolderInstance.Name = "AnyFolderNameYouLike"
	    myFolderInstance.Parent = player

	    local myValueInstance = Instance.new("IntValue")
	    myValueInstance.Name = "AnyValueNameYouLike"
	    myValueInstance.Value = 100
	    myValueInstance.Parent = myFolderInstance

	    spawn(function()
		    while true do
			    wait(2)
			    myValueInstance.Value = myValueInstance.Value + 100
		    end
	    end)
    end)

Then you can do something like this in each client:

while true do
	wait(2)
	local Players = game:GetService("Players")
	for _, player in pairs(Players:GetPlayers()) do
		local folderInstance = player:FindFirstChild("AnyFolderNameYouLike")
		if folderInstance then
			print(player.Name .. ': ' .. folderInstance.AnyValueNameYouLike.Value)
		end
	end
end

And you will see the updated values as set on the server (for each player) get printed out on the client also updated.

BUT of course in a real game you would not loop through the values like that you would bind to change events for the folder such as GetPropertyChangedSignal. IE Something like this:

local player = game.Players.LocalPlayer
player.AnyFolderNameYouLike.AnyValueNameYouLike:GetPropertyChangedSignal("Value"):Connect(function()
     print(player.AnyFolderNameYouLike.AnyValueNameYouLike.Value)
end)

Hopefully this will help someone else who didn’t understand the basic Roblox propagation paradigm.

For all you native Roblox coders out there, something like this is kind of magical and doesn’t happen in many other languages - you often have to code it yourself.

4 Likes

Follow up on this. I’ve realized you don’t need to bind GetPropertyChangedSignal to every value in your player on the server. You can optimize this and just trigger one function on the client side by watching only one value for updates.

The trick would be to update all the user values on the server and THEN update one single value that you have connected an event to.

So, for example, let’s say you made a folder in player called Data and then in data you added the intVal of Update

All you would need to do is player.Data.Update.Value = player.Data.Update.Value + 1 and then the server would know to look at all the other values.

It would work something like this:

  1. Update multiple values in the player (on the server) such as player.Data.Cash.Value = 123, player.Data.XP.Value = 123, etc.
  2. After your updates do player.Data.Update.Value = player.Data.Update.Value + 1
  3. This will trigger the GetPropertyChangedSignal for Update on the client and now you can be sure that XP and Cash are the latest and you can update your UI accordingly.

This is useful because you can change lot’s of values for a player in one shot on the server, and then trigger the client to deal with them in one shot just by watching Update