Better way of creating leaderstats values

As a developer, it is currently too annoying, not necessarily hard, to make leaderstats for a player.

This has been something I have been thinking about for the last months. Which is about how weird making a leaderstats folder inside of a player is.

Why isn’t there any function to the player to set a leaderstats, making a folder called “leaderstats” SOUNDS deprecated but isn’t.

Some time ago I have tried to create a leaderstats module (never ended up finishing it) on which you have functions that you can do to players, and blah blah blah. Might remake it and release it.

It was surprising for me, I couldn’t find anything or anyone talking about making leaderstats being weird. I thought roblox would have a function based solution at this point.

There’s nothing particularly wrong with the current system. Other than the annoying way to create values.

An example of an implementation would be:

game.Players.PlayerAdded:Connect(function(plr)
    local cash = plr:CreateStats("Cash", 0) --SetStat? Not sure.

    local points = plr:CreateStats("Points", 0)

    -- annoying DataStore work down here lmao
end)

This would be especially beneficial when creating a LOT of values.

This would have been the code currently, where none of this exists yet.

game.Players.PlayerAdded:Connect(function(plr)
    local fold = Instance.new("Folder", plr)
    fold.Name = "leaderstats"

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = fold

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Parent = fold

    -- a bit too long for something so simple, right?

    -- datastore work or whatever lmao
end)

While there could have been some places in this player added event on which I could have improved, for the most part they’re smaller changes. Now come back to the implementation I talked about.

It’s way smaller isn’t it?

Sometimes I’ll be recreating DataStores and leaderstat systems and be extremely annoyed because there’s a LOT of values to make.

This wouldn’t be a hard feature to implement at all, and I think it could be a good improvement and make things easier for developers. Even if it was just a proxy to leaderstats.

Also, these lines are so annoying sometimes also here on the DevForum with people who will need DataStore help and etc, and they might have 30 values they need to create. For them, that’s 60 lines they don’t need to write anymore if this was created.

That’s just an example implementation, there are other ways to go about it which would result in easier code.

1 Like