Exp doesn't save

I have a leveling system but, the xp always seems to get smaller and smaller, when the player rejoined, instead of keeping the original Xp.

script:

local Exp = Instance.new(“NumberValue”)
Exp.Name = (“Exp”)
Exp.Parent = plr

local Level = Instance.new(“NumberValue”)
Level.Name = (“Level”)
Level.Parent = plr
Level.Value = 1

local ExpReq = Instance.new(“NumberValue”,plr)
ExpReq.Name = (“ExpRequired”)
ExpReq.Value = Level.Value * 150

– Level Up & Exp

Exp.Changed:Connect(function(Changed)

  if Exp.Value >= ExpReq.Value then
  	
  	Exp.Value = Exp.Value - ExpReq.Value
  	
  	Level.Value += 1
  	ExpReq.Value = Level.Value * 150 
  end

end)

local CoinData
local ExpData
local LevelData
local ExpReqData

local worked, Error = pcall(function()

  CoinData = myDataStore:GetAsync(plr.UserId.."-Gold") -- Save CoinData
  -- Save First Coin Given Data
  
  ExpData = myDataStore:GetAsync(plr.UserId.."-Exp")
  
  LevelData = myDataStore:GetAsync(plr.UserId.."-Level")

end)

if worked == true then

  Coin.Value = CoinData
  Exp.Value = ExpData
  Level.Value = LevelData
  ExpReq.Value = ExpReqData

else

  warn(Error)

end

end)

game.Players.PlayerRemoving:Connect(function(player)

local worked, Error = pcall(function()

  myDataStore:SetAsync(player.UserId.."-Exp",player.Exp.Value)
  myDataStore:SetAsync(player.UserId.."-Level",player.Level.Value)
            myDataStore:SetAsync(player.UserId.."-ExpRequired",player.ExpRequired.Value)

end)

if worked == true then

else

  warn(Error)

end

end)

2 Likes

Do you mean ExpReqData doesn’t save or Exp?

1 Like

the exp is what I’m talking about.
expreq is the required amount of exp in order to lvl up.

There is the issue you’re removing the xp instead of just parenting the xp

1 Like

I dont quite understand what you mean. Can you elaborate?

1 Like

nvm i fixed the issue by making another script to track the changes instead of checking everytime the player joined

1 Like