Hello dev forum,
So im curious how people do total value stats. If you dont know what im talking about, in games like ninja legends even if u rank up (reset stats) It still remember your total. Im just curious what concept they use for this.
Hello dev forum,
So im curious how people do total value stats. If you dont know what im talking about, in games like ninja legends even if u rank up (reset stats) It still remember your total. Im just curious what concept they use for this.
I’m confused, correct me if I’m wrong here, are you asking the following:
Lets say you have three values. XP, Level, and Total XP. Your XP determines the level you are. Lets say, you need 200 XP to reach Level 2. Once you have 200 XP, it changes your level to level 2 and changes your XP to 0, while still keeping your Total XP at 200.
Is this what you’re asking?
I think I know what you are talking about here.
So, let me provide a straight, simple example;
Let’s say we have a coins integer value. If we wanted players to see our total in a settings tab or something along the lines of that, we’d add a second integer value. Every time the player acquires some more coins, a script will add the coins to the first and second value, except the second value won’t be used for in-game transactions, instead it will be a lingering value that can only be added on.
If you’ve caught on, fantastic! Otherwise, let me say one more thing. The first value will be the big number on the player’s screen, telling them how much currency they have. The second currency will be a little number in the settings, telling them how much they’ve made in their entire playthrough. The only time the second number will be changed is when it’s being added to.
Thanks for reading!
-sick
So lets say u have a currency known as points. And lets there us a place which resets ur current points. But some games have a feature called total points which adds up all the points u ever had. Im curious how do u make this?
Thank you for answering! But my question is if the player resets his current or the big number on the screen, then how will u add the total? I know we can make like
total = current
because if ur current is 0 (reset) but u had 100 once it will only show 0
They’d probably have a different datastore which tallys up the total amount of points you’ve ever had, and then another datastore that would tally how much points you currently have
You wouldn’t use total = current
per say.
Let me further illustrate the point above. Lets use the example of someone gains a point whenever they touch a part, and there points reset whenever they touch another brick. (Don’t actually use this code in a game, this isn’t optimized nor does it have things that you’ll need for this to work such as datastores, debounces, optimization and more, it’s simply here to illustrate a point.)
local PartToGainPoints = workspace.Part1
local PartToResetPoints = workspace.Part2
local function AddPoints(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then -- make sure it's a player that touched this part
local plrValue = game.Players:FindFirstChild(hit.Parent.Name) -- find the player
plrValue.leaderstats.Current.Value = plrValue.leaderstats.Current.Value + 1 -- add a point to the current value
plrValue.leaderstats.Total.Value = plrValue.leaderstats.Total.Value + 1 -- add a point to the total value
end
end
local function ResetPoints(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then -- make sure it's a player that touched this part
local plrValue = game.Players:FindFirstChild(hit.Parent.Name) -- find the player
plrValue.leaderstats.Current.Value = 0 -- we reset the current points value, but not the total points value
end
end
PartToGainPoints.Touched:Connect(AddPoints)
PartToResetPoints.Touched:Connect(ResetPoints)
You’ll notice that when we reset the points, we only reset the ‘Current’ value, we don’t reset the ‘Total’ value. Obviously these need to be Datastored accordingly if you want them to keep the values, but I believe this is the concept you’re trying to understand.
If you have an experience to level formula and you know the player’s level and their experience into their current level then you should be able to work backwards in order to ascertain the total amount of experience they’ve earned.
Let’s say the experience formula is (currentLevel ^ 2) * 100
, at level 1 the player requires 100 experience to reach level 2, at level 2 the player requires 400 experience to reach level 3, at level 3 the player requires 900 experience to reach level 4 and so on (exponential formula).
Now assume we want to calculate the total experience of a player that’s level 10 and is 1,000 experience into their current level.
All we need to do is plug their level into the formula for each level and add the remaining experience to the result.
local totalExperience = 0
for i = 1, 10 do
totalExperience += (i ^ 2) * 100
end
totalExperience += 1000
print(totalExperience) --39,500