How to make a simple global leaderboard

(line 64) new.Image.Place.Text = number

What is Place? It shows an error that “Place is not a valid member of ImageLabel”.
I know this post is pretty old, but if somebody is still around please help.

1 Like

Name your text label inside the ImageLabel Place. The code simply needs to reference that text label.

For a working demo that you can copy / look at for reference see the OP.

2 Likes

How could I change this to fit a monthly basis?

1 Like

How this can be accomplished was explained in the OP:

2 Likes

Will this automatically create a new key after a month? And will it keep going after the first month?

1 Like

It should because os.date() and os.time() change automatically over time – since the key is referring to that variable, it’ll update as soon as the month changes.

1 Like

The key will be as accurate as when it is generated. So if your server lasts multiple months, you’d likely want to update the key. Essentially instead of using a bunch of calls to remove data, you’re just using new keys instead.

3 Likes

To reset a player’s stats you would have to remove their value from the ordered datastore of set it to 0. Note that if you have a datastore which saves this value as well, you’d have to reset both.

1 Like

Ordered datastores have the same set / remote methods as regular ones, the only difference is that ordered datastores can only store numerical values.

Using datastores in they way your describing is a little off-topic for this tutorial, so if you have further questions you might want to start a new thread.

local sf = sg:WaitForChild("ScrollingFrame")
Attempt to index nil with "WaitForChild"

I also followed your example but it gives me this error

1 Like

This means that the Instance you’re calling :WaitForChild() on does not exist (which would be the variable of “sg”).

Ensure that the Instance that is stored in the “sg” variable is not nil at the time of referencing it to prevent the script from erroring.

Example check:

if sg then
    local sf = sg:WaitForChild("ScrollingFrame")
else
    warn("No value stored for 'sg'/the Instance does not currently exist.")
end
2 Likes

As @StrongBigeMan9 explained, this is because you haven’t properly defined the sg (the SurfaceGui) variable.

See the original post for a working demo & tutorial on how to properly get started.

2 Likes

@ThatTimothy Do you have any idea on how I can achieve something similar to the circled part of this leaderboard?
Screenshot 2021-03-28 135611

3 Likes

It’s just different ui styling. If the position is equal to 1, then use a different sample frame. This can be customized however you want, with different layouts like the one above.

3 Likes

Since my leaderstat value is a decimal, how would I make it work with that? Will it work the same if I use :GetDataStore instead of :GetOrderedDataStore?

3 Likes

OrderedDataStores only accept integers, which means that you would need to use math.floor or math.ceil (documentation for that can be found here) in order to convert the decimal into a whole number.

You wouldn’t be able to use :GetDataStore for this kind of leaderboard because the values are not sorted in regular DataStores.

2 Likes

I tried them both but the value on the leaderboard is still nil.

(Error)

Could you provide the code you’re using?

The OrderedDataStore can only store numerical integers, so you need to make sure you’re saving valid values.

Several solutions:

local someValue = 931.3819199293
--Just make it an integer
math.floor(someValue) --> 931
local someValue = 931.3819199293
--Store a certain number of decimal places:
local storedValue = math.floor( someValue * 1000 ) --> 931381
--And then convert is back when displaying:
storedValue / 1000 --> 931.381
3 Likes

Thanks very useful it helps a lot of new developers like me :slight_smile:

1 Like

How do I make it so that it shows people who are not in the server?