yeah but im confused because i want to make the leaderboard work with scores in the roblox leaderboard, and im asking where would i put it in the script that gets a new key everyday but also make it so that it only gets the amount of score a player got in the single day (since points in my game save), i just thought i would have to create a separate value and reset it daily, aslo, ince the player has their data saved, they would basically be on the leaderboard everyday, since it does not track the survivals they got in that game
Essentially, yes, you would store a second value which resets daily. Every time they gain a point, add to it. When they log on a new day, reset that value. Then, you can save the value with the unique key.
The unique key for the global datastore just makes sure that players who don’t log on on a given day don’t show up.
Now your answer does say we have to create a unique key every day, and you already have the lines for the creation of a new key, but where in the script would i put it? Under the variable that defines the data store? Or somewhere else such as in the while true do loop?
Additionally, how could I make a value on the player reset everyday? I was thinking that you just reset it through all servers when a new day starts, but that would not work for if a player isn’t in the game, so make it that it resets the score at a time, even if the player isnt in game
And one more thing, can i modify the leaderboard guis like the textlabels without breaking the script? Because I want to make it different
local dateTable = os.date("*t", os.time())
local key = "Y:"..dateTable["year"].." M:"..dateTable["month"].." D:"..dateTable["day"]
--Unique key for each day
local dataStore = dataStoreService:GetOrderedDataStore("LeaderboardName" .. key)
Where you define the retrieved datastore you would use the unique key. Note that if a server lasts for longer than 24 hours, you would want to update this again to avoid displaying data for the previous day.
Simply store the day that you’re collecting data for
--On Player Join
local dateTable = os.date("*t", os.time())
local keyForToday = "Y:"..dateTable["year"].." M:"..dateTable["month"].." D:"..dateTable["day"]
if playerData.lastTimeDataStored ~= keyForToday then
playerData.dataValue = 0 --Reset the value
playerData.lastTimeDataStored = keyForToday --Reset the value keeping track of the last reset
end
____
--When they get points
playerdata.dataValue += pointsAwarded
This just makes sure that if a player gained data on a previous day, that it resets before you save that value to the current day’s leaderboard. (If Player1 had 50 points the previous day, we should start at 0 today not 50)
You can customize the leaderboard however you like! Just be aware that if you change the names of stuff, you need to change them in the script aswell.
Thank you for helping but about what you said for the server lasting more than 24 hours and having to update the leaderboard, how would I do that, because most of the time on my game actually the server actually lasts 24 hours or when a new day starts (12am). Sorry for being a bit annoying to btw, i just really want a daily leaderboard in my game
You would just make a loop or however you want to go about it that every time the key changes, you set the dataStore
variable to the new one.
So do you have a line of code to explain that, because the only thoughts i have is to reset the data store daily like the value, or reset it when the data store changes (which i don’t know if that’s possible)
I’m thinking it of something like changed
Also does the leaderboard update the amount players get in day and not update only when a new day starts for example the daily leaderboard updates for new players to try and get on itso players get points while in game, would the leaderboard update the score they got every minute or something?
You would just create a loop which runs every 60 seconds or however often (you could do it inside the actual loop in the code), which checks if the key has changed. If it has, update the dataStore
variable.
Changed is for value objects, not variables. You would just check if previousValue ~= newKey
.
This basic leaderboard just sorts the values YOU give it. Any more complicated behavior you have to add on your own, such as resetting the values you give it daily.
Resetting the key for getting the data JUST prevents you from displaying the previous day’s data. You also need to reset the value you give the leaderboard daily, with methods I’ve talked about above.
Suggestion
If you have any more questions such as exactly how to set up what I’ve said, your best bet would be asking in #help-and-feedback:scripting-support. I can explain the methods you would use, but I can’t make your game for you. Also, make sure to condense your replies into one instead of three in order to not create unnecessary post bloat. (You can edit replies if you need too)
How could I make this a leaderboard but only for people in the server?
Instead of using datastores, you would just save all the data into a table, and use table.sort to sort the data. Then, display it in the same way.
Thats my problem though… I saved it all in a dictionary and I am still stuck trying to figure out how I can sort it…
Here is what I mean:
local kills = {
["SpacePuppy2"] = 123 -- Say I have 123 kills.
["Player2"] = 999 -- They have 999 kills
["Player3"] = 0 -- They have zero kills.
}
I then get these values later by doing something like:
local killsValue = kills[playerName]
I tried using a function to turn them into arrays so I could sort them and it worked, but now I have no clue how to get the players kills from the array. If I could just figure this out my leaderboard should be working!
(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.
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.
How could I change this to fit a monthly basis?
How this can be accomplished was explained in the OP:
Will this automatically create a new key after a month? And will it keep going after the first month?