Hello everyone! ヽ(>∀<☆)ノ
So I present to you my first public module ever: EZStats!
What does it do?
Well… It’s a wrapper for leaderstats!!
You create a new instance of the wrapper, and from there you can modify stuff!
Why should I use it over manually creating leaderstats?
In my opinion, it is more simple than manually doing it, and also consistent if you’re using a framework. if you don’t, try it it out! It helped me with my procrastination which was the result of code structure design. I dunno if you think the same though. ( ̄▽ ̄)
API
-
EZStats.new(player: Player)
Description: Instantiates a copy of EZStats
→ Returns a copy of EZStats-
_lead: the leaderstats
Folder
-
_lead: the leaderstats
-
EZStats:Create(valueType: string, valueName: string)
Description: Creates aValueBase
of typevalueType
, with NamevalueName
valueType
can beinteger
,number
andstring
, case insensitive (that means you can put “iNTegEr”)
→ nil -
EZStats:ListenTo(valueName: string, eventName: string, callback: function
Description: Adds event listenercallback
to eventeventName
of valuevalueName
→ RBXScriptConnection -
EZStats:Set(valueName: string, value: any)
Description: SetsValue
ofvalueName
tovalue
. IfValue
doesn’t accept type ofvalue
, a warning will be throwed. -
EZStats:Get(valueName: string)
Description: Gets theValue
ofvalueName
→Value
ofvalueName
-
EZStats:DestroyValue(valueName: string)
Description: CallsDestroy
onvalueName
→ nil
How to use
To use EZStats, you have to require the module, then create new instances of it on the .PlayerAdded
event and cache it. Here’s an example:
-- Require EZStats
local EZStats = require(PATH_TO_EZSTATS)
-- Cache for players
local plrs = {}
-- PlayerAdded event
game.Players.PlayerAdded:Connect(function(plr: Player)
-- Cache a new EZStats instance
plrs[plr.UserId] = EZStats.new(plr)
-- Index the instance
local plrLead = plrs[plr.UserId]
-- Create an IntValue named "Cash"
plrLead:Create("integer", "Cash")
-- Listen to the .Changed event
local conn
conn = plrLead:ListenTo("Cash", "Changed", function(newVal)
print("Detected change: " .. newVal) -- "Detected change: 20"
conn:Disconnect()
end)
-- Print out value of "Cash"
print(plrLead:Get("Cash")) -- 0
-- Set "Cash" to 20
plrLead:Set("Cash", 20)
print(plrLead:Get("Cash")) -- 20
plrLead:Set("Cash", 19)
-- Destroy the value (you probably won't do this in your game)
plrLead:DestroyValue("Cash")
end)
-- Remove player from cache (Microsoft doesn't hire people that introduce memory leaks!)
game.Players.PlayerRemoving:Connect(function(player: Player)
plrs[player.UserId] = nil
end)
Can I access it from client?
Yup! Internally everything is a BaseValue
(or else the leaderstats won’t appear, won’t they?) so you can access it via LocalPlayer.leaderstats.valueName
. Or you can manually replicate the EZStats instance from the player’s cache (you don’t even need to do this if you’re using a framework!).
Where to get it
fun fact: most of the code is just checking the arguments