Global leaderboard doesn't refresh correctly

Here comes MessagingService to save developers! :sparkles:

Pros:

  1. No delays or chances of corruption unlike datastore (happens if you write data often, in this case your auto-refreshing feature for the leaderboard).
  2. Can work across all servers.
  3. You can pass data without having to waste your datastore requests.

MessagingService would probably be less efficient than an OrderedDataStore. You can use data stores past their budget - all the budget means is requests following will be subject to throttling.

With MessagingService, you would need to send the data, get the data, check the player there already exists, update their data there, and if requests are at all delayed and the player joins back to a different server (leave and insta-rejoin), it could cause some big issues. OrderedDataStore would probably be better. Cool idea!

Uh what do you mean, how am I supposed to implement it to my code? I mean as for now I went back to the old working script but meanwhile I’m still trying to fix the one you try to help me to fix.

Completely agree, I’ve reviewed the topic again and now understand clearly the issue. :slightly_smiling_face:

1 Like

You would put it in the PlayerAdded code. It saves cash every time it’s changed.

Your script doesn’t have a player added code uh only player removing

My bad. Add this:

Players.PlayerAdded:Connect(function(player:Player)
    local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
    cash:GetPropertyChangedSignal("Value"):Connect(function()
        local success, result = pcall(dataStore.SetAsync, dataStore, player.UserId, cash.Value)
        updateLeaderboard()
    end)
end)

ik i keep saying this but it’s really not a great method


wait but now 2 scripts auto update leaderboard, should i change the autoupdate?

//edit: i mean 2 functions

Don’t update it when the cash value changes, just for the loop.

u literally said to update it in your reply so im confused

Yeah, i got it wrong. Leave the updating to the automatic loop. Sorry about that…