Concerned of syncing a leaderboard's & workspace's value

English version:

Hello, is it possible to somehow sync a numeric leaderboard value with a workspace’s value? As I’m very concerned about that since I could have to cancel one of my 18 projects due that or try something else. If anyone knows if it’s possible… It’ll be valuable to tell.

(P.S: Sorry for any possible grammar failure. I’m Spanish not English)

Version Española:

Hola, es posible de alguna manera sincronizar un valor numerico de la tabla de clasificacion con un valor del workspace? Estoy muy preocupado desde que podria ser que tuviera que cancelar uno de mis 18 proyectos por eso o intentar otra cosa. Si alguien sabe si es posible… Sera valuable decirlo.

(P.S: Perdon por algun fallo de ortografia. Soy Español, no Anglosajon)

You can use the Changed event to update the leaderboard value when the workspace’s value changes to keep them in sync.

Example:

local workspaceValue = workspace.WorkspaceValue
local leaderboardValue = game.ServerStorage.LeaderboardValue

workspaceValue.Changed:Connect(function(newValue)
   leaderboardValue.Value = newValue
end)

Not fully sure that I’ve fully understood the question you are asking.

2 Likes

Hey dani31c,
could you clarify what you mean by workspace's value??
In addition, @UnderMyWheel’s solution works perfectly, however it would be best practice to use :GetPropertyChangedSignal() which would be optimal

In this case, the GetPropertyChangedSignal does not need to be used at all as Value instances have a non-inherited Changed event that will only fire when the Value property changes.

This means there are absolutely no benefits to using GetPropertyChangedSignal and using the Changed event is the best practice.

No need, Changed is modified on ValueBases to fire only on the Value property change.

If you wanted to listen for another property change, like Name, you would need :GetPropertyChangedSignal("Name")

1 Like

@UnderMyWheel @incapaxx Yes you’re totally right, my bad! Misunderstood myself

1 Like

It means syncing a leaderboard stat (numeric value) with a numeric value that belongs to workspace.

I think I know how to use UnderMyWheel’s solution and I think it works.

while true do
local WMoney = game.workspace.Money.Value
local SMoney = gameServerStorage.Money.Value
Wmoney.Changed:Connect(function(WMoney)
SMoney = WMoney --- This is to adapt it shall work.
wait (0.1)

There are a few things wrong with your code

  1. It is a loop meaning it is going to attempt to create a Changed event every tenth of a second
  2. The Changed event is part of numerical value instance, but you are currently indexing the Value property of the numerical value and then attempting to use the Changed event

Your code should look like:

local WMoney = workspace.Money
local SMoney = game:GetService('ServerStorage').Money

WMoney.Changed:Connect(function(newWMoneyCount)
   SMoney.Value = newWMoneyCount
end)

Then, how about looping it and making instead to every likelly… 0.1 seconds it to update the value? Would that work? I mean, Smoney = WMoney

While true do
local WMoney = game.workspace.Money.Value
local Smoney = game.ServerStorage.Money.Value
Smoney = Wmoney --- Updates the value to current.
wait(0.1)

The code above will set the Value of SMoney when the Value of WMoney changes keeping them in sync.

Is that not what you are looking to do?

Yes, but a way to simplify it. Instead. So I do lighter codes.

In what way are you looking to simplify it?

Personally, I find it cleaner to use the code example I have provided you with. In addition, running a loop to update the values every .1 is inefficient.

Well, I think that script will work well. But I need to secure it only runs when value changed. Any way for that?

Changed will only be fired when the Value changes.

But will the script actually loop and run every time the value changes?

Any code within the Connect function will run when the event is fired.

Value.Changed:Connect(function(newValue)
   print('Value changed to '..newValue)
end)

The code above will print to the output “Value changed to …” every time the value changes.