Help for a doublexp system

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 ?

1 Like

Make a function that checks whenever a player is about to gain new XP, take that value and multiply it by 2.

1 Like

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 have try but i don’t know what i can write for this…

I have 300 script to modify with your method ^^ i want just one script for modify all exp income and double

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.

If you want more information ask me then.

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”.

Thank you :slight_smile: it’s my request and you have send the solution!

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 ^^

Could you show me your level up system?

function onXPChanged(player, XP, level)

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

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.

2 Likes