Cool model! I have my own leaderstats script but they DEFINITELY aren’t as flexible as your model. I’ll definitely try this out
Ahhh that makes more sense, ill probably use it for shop, coins, etc.
This is a really nice module, really easy to use and user friendly!
Can you provide an example usage of StatsManager:SetTag(“YourTagGoesHere”)? I’m having trouble on how to use it and what is it used for.
The code you mentioned, StatsManager:SetTag()
, doesn’t need to be included if you are setting up your StatsManager for the first time. However, if you are migrating from an existing datastore, you can use a string as the parameter to specify a datastore tag to combine. Hopefully this cleared it up, let me know if you still have questions.
Hello, I’m currently making a ban system with this module and I have a question.
Does StatsManager access the data of players that already have data in StatsManager when they’re not in game? Just wondering so that my unban function for my ban system is really working.
Hi there, the current version of StatsManager only lets you access data for the specified player by accessing and reading data in the Player
object while they are in game. Your use-case, however, is valid and I would be more than willing to add a method to access player data via UserId if that is the type of solution you are looking for. I think I can get this added to the module in approximately a weeks time.
I’ve created a solution for your request, and it should be available either through the Roblox Link or GitHub. I will create release notes for this soon when I get time to.
The following syntax should be
StatsManager:EditOfflineData(userId, callback)
and in practice, it looks like this:
local StatsManager = require(ReplicatedStorage.StatsManager)
StatsManager:EditOfflineData(69896869, function(stats)
stats.Cash = 9999999999
end)
The reason why there is a callback function is so that the stats can be garbage collected after it is done being edited. You don’t really have to worry about this information, but do make note that it will be easier to use on your end :).
Thank you for this, you’ve came up with a solution faster than I expected!
Update v3.0 - Edit offline data!
It’s been a while since the last major update, but this time I am giving you the ability to edit data for players who aren’t in-game.
Some minor things have been changed, as well as some bug fixes, but nothing should break your code, so it is completely safe to update to the latest version if you are planning on doing so!
Edit offline data
You can finally edit data for players who are not in-game! This is useful for ban systems or other moderation tools. The following example will edit the amount of cash my user has when I am not logged in.
local StatsManager = require(ReplicatedStorage.StatsManager)
StatsManager:EditOfflineData(69896869, function(stats)
stats.Cash = 9999999999
end)
The method includes a callback function. Any changes made to stats within the callback function will save after the thread has finished executing. The aim of this implementation is to reduce calls to DataStore, as well as ensure proper garbage collection, which can be time-consuming to implement manually.
Finally, I improved documentation on the DevForum page to make it easier to understand.
As always, you can grab StatsManager from Roblox or GitHub, the choice is yours!
Granted the use case of viewing offline data is incorporated into this function right? I don’t need to edit data as much as view it for offline people.
This is built right into the EditOfflineData()
function. The stats should viewable and modifiable. You did raise a valid point however, that the save function for editing offline data does not need to be called if no data has been changed. This needs to be implemented for the DataStore2 wrapper to reduce Datastore calls, however if you are using the ProfileService wrapper (which StatsManager sets by default), it should already have this built-in.
Is it possible to loop through every single one of the stats given by the :GetData() function? I’m assuming :GetData() returns a table but I’m unable to loop through it. Unless if it’s impossible to do so at the moment.
:GetData()
returns a metatable, if you know what that is. It allows values to automatically update and save whenever values are changed. What this basically means is that you can’t loop through the values normally, as it’s not technically a real table of values. In most cases, you should know what values you are changing and avoid looping through them. However, a common workaround is to use the template table to index each value. If you have a valid use-case, let me know.