Hi, i try to make a doublexp system in my server, i search a function for calculate the difference when the actually xp of player and a new xp income…
Exemple:
The player have 550 xp and he gained 50 xp
The new xp of player is 600, i search a function for calculate the difference between the old xp (550) and the new xp (600), the function will be print (50) if it’s work good
You know a function for calculate this difference ?
Double XP doesn’t work by calculating differences and then adding that same value (which in itself is useless because you know how much is getting added, so you could’ve did it twice).
To make double EXP, you take the incoming amount of EXP and multiply it by two, then add it to the player’s EXP value. Assuming (and hoping) that you have one function kept around that is responsible for adding EXP in, you simply need to check if the player is eligible for double, multiply the passed value by two and then add it to their current EXP count.
I think that’s basic math, here is a small example.
local XpValue = YourXpValueHere --Let's take an example that you have 100 Xp
local CurrentXp = XpValue.Value --100
XpValue.Changed:Connect(function() --The player have 120 Xp right now.
local ChangedValue = XpValue.Value
local Difference = ChangedValue - CurrentXp
print(Difference) --20
XpValue = XpValue + Difference --Since the player already got 20 Xp, if you add 20 Xp more, this will count as 40 (20*2)
CurrentXp = ChangedValue + Difference
end)
Insert this in your leaderstats script, after creating the stat values.
That’s a fundamental flaw in your system that needs to be fixed then. You should have only one way of adding EXP to the player and any script wanting to give players EXP should be doing it through that, instead of doing it their own way and resulting in - as you say - “300 different EXP scripts to modify”.
I have test and it’s working good, but if i gain 1 level, my xp stay in 0 because the difference is -3000 due to a passed level xD i don’t know if we can fix that
Exemple:
Im level 1 with 200 exp / 300 xp
I gain 100 xp with the kill of monster, so im now level 2
But i don’t have 100 xp more because the XpValue is now 0 ^^
Ok, i think you just need to merge both scripts, i don’t know if this works, if not, then i will change your current level system to help you.
local XpValue = XP --Let's take an example that you have 100 Xp
local CurrentXp = XpValue.Value --100
function onXPChanged(player, XP, level)
local ChangedValue = XpValue.Value
local Difference = ChangedValue - CurrentXp
print(Difference) --20
XpValue = XpValue + Difference --Since the player already got 20 Xp, if you add 20 Xp more, this will count as 40 (20*2)
CurrentXp = ChangedValue + Difference
---Your script starts here:
if XP.Value>=level.Value * 100 and level.Value < script.LevelCap.Value then
XP.Value = XP.Value - level.Value * 100
level.Value = level.Value + 1
end
I hope this helps, and sorry, because i didn’t respond you in 4 hours.