How would I make a script that would multiply XP received. For example I want to make an event and people would receive x2 xp.
✓ ANSWER ACCEPTED
EXP RPG script?
1 answer
✓ Accepted answer
This is a very vague question, and since it includes no code, I'll infer how you've set it up.
I'm assuming you're using an IntValue to store each Player's XP somewhere, and adding to that value from numerous sources.
You can use the Changed event of ValueObjects to catch an update to the value, and then compare the current value with a saved "previous" value. This has to be done carefully, so as to avoid an infinite loop:
local xp = Game.Players.LocalPlayer.leaderstats.XP --I'm assuming this is where you would have it. This should be in a LocalScript inside of the PlayerGui
local prev2 = xp.Value
local prev = xp.Value
xp.Changed:connect(function()
if prev == prev2 then
local diff = xp.Value - prev
prev = prev + diff*2 --doubles the given XP
xp.Value = prev --fires the Changed event again, but this time the `if`check fails
else
prev2 = prev
end
end)
This can still error if multiple things try to give XP at the exact same time, so be careful about that.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
What exactly do you want with this?