Have stat xp be based around its needed xp

So when the player hits a enemy with a sword, they gain melee stat xp.
And i tried making the XP be based around the needed xp to level up the stat.
What i got right now:

local function XP_Formula()
	local Stats = DatastoreHandler:Get(plr,"Stats")["Melee"]
	return (Stats.XP_Needed/20)
end

Is DatastoreHandler supposed to be a DataStore or a creation of your own? Because Get doesn’t exist in the DataStore. Read the documentation about the DataStore to get more information.

Otherwise, please show us what’s supposed to be DatastoreHandler for more help.

that has nothing to do with the forumla

when the stat is level 1, the needed xp is 100. Now I would need to get how much XP i would need to give to the player each time they swing. For example: XP Needed = 100, each swing = 20 xp points

This is just basic math. 100 / 5 = 20.

Code:

local function XP_Formula()
	local Stats = DatastoreHandler:Get(plr, "Stats").Melee

	return Stats.XP_Needed / 5
end

You didn’t mention a formula in your question, in fact your question wasn’t very clear. I hope Katrist has the answer you need, I wish you the best for your project.