This is the LocalScript
01 | xpChanger.OnClientEvent:Connect( function (xpGiven) |
02 | -- Save xp |
03 | local curXp,curLvl = saveReturn:InvokeServer(xpGiven) |
04 | -- Math |
05 | local percentage = curXp/( 10 *curXp) |
06 | local newXOffset = percentage*xOffsetXp |
07 | -- Apply |
08 | xpDisplay:TweenSize(UDim 2. new(xScaleXp,newXOffset,xScaleXp,xOffsetXp), 'Out' , 'Quad' ,. 5 , false , nil ) |
09 | lvl.Text = 'Lvl: ' .. tostring (curLvl) |
10 | xp.Text = 'Xp: ' .. tostring (curXp) |
11 | end ) |
This is the Script
01 | local bool,message = pcall ( function () |
02 | saveReturn.OnServerInvoke = function (plr,xpGiven) |
03 | local key = 'Player-' ..plr.userId |
04 | local curLvl = lvlDataStore:GetAsync(key) |
05 | local lvlEquation = 10 *curLvl |
06 | -- Adds lvls and sets xp |
07 | if curLvl = = 0 and xpGiven = = 10 then |
08 | xpDataStore:SetAsync(key,(xpGiven - lvlEquation)) |
09 | lvlDataStore:SetAsync(key,(curLvl+ 1 )) |
10 | print (curLvl+ 1 ) |
11 | return xpDataStore:GetAsync(key),lvlDataStore:GetAsync(key) |
12 | elseif lvlEquation = = xpGiven then |
13 | xpDataStore:SetAsync(key,(xpGiven - lvlEquation)) |
14 | lvlDataStore:SetAsync(key,(curLvl+ 1 )) |
15 | print (curLvl+ 1 ) |