Five weeks into scripting

After 5 weeks of scripting, This is as much as I can remember in terms of creating leaderstas. Are their any ways to make this better?

local player = game:GetService("Players")


	local leaderstats ="Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	--//Adding a "Stage" count to the leaderstats
	local Stage ="IntValue")
	Stage.Name = "Stage"
	Stage.Value = 0
	Stage.Parent = leaderstats
	local XP ="IntValue")
	XP.Name = "XP"
	XP.Value = 0
	XP.Parent = leaderstats
--//Connects the MinV & MaxV to the Currency using an intValue.
	local MinV = game.ReplicatedStorage.CurrencyValue:GetAttribute("MinV")
	local MaxV = game.ReplicatedStorage.CurrencyValue:GetAttribute("MaxV")
	local Currency ="IntValue")
	Currency.Name = "Coins"
	Currency.Value = MinV
	Currency.Parent = leaderstats
	Currency.Value = math.clamp(Currency.Value, MinV, MaxV)

Instead of making a whole other line of code for parenting the IntValue, try this:“IntValue”, leaderstats)

No, that is less performant PSA: Don't use with parent argument

And for the script, everything looks fine although I’m not that experienced with leaderstats.


When it comes to comments, you should be commenting why not what. Eg, it is easy to see that you are creating an integer value called Stage, but it would be more meaningful to explain why you are doing so.


I used to do it like that, but I had several people tell me not to as it causes performance issues.


Instead of doing Currency.Changed:Connect()
I would recommend using Currency:GetPropertyChangedSignal("Value"):Connect() as it only fires when the value changes instead of any property change.

I would also recommend to rename the variable for the players service to “Players” to make it different from the parameter name.