I'm currently working on an RPG game and I've encountered a problem while updating stats, more specifically, Experience points.
My problem is if someone levels up and immediately leaves, his XP will not reset, and he will have the same XP that he had before leveling up.
Help is much appreciated!
local _UpdateData = function(__Player, __Form)
local _Character = __Player.Character or __Player.CharacterAdded:Wait()
local _Humanoid = _Character.Humanoid
local __UserID = __Player.UserId
local __Level = __Player.leaderstats.Level.Value
local __Experience = __Player.leaderstats.Experience.Value
local __Gold = __Player.leaderstats.Gold.Value
local __Armor = 0
if __Experience >= __Level * 50 then -- level up
local _UpdatedExperience = __Experience - (__Level * 50)
__Player.leaderstats.Experience.Value = _UpdatedExperience
__Player.leaderstats.Level.Value = __Player.leaderstats.Level.Value + 1
_Humanoid.MaxHealth = (__Player.leaderstats.Level.Value*25)+__Armor
_Humanoid.Health = (__Player.leaderstats.Level.Value*25)+__Armor
end
local _Success , _Error = pcall(function()
if __Form == 0 then
_Humanoid.MaxHealth = (__Player.leaderstats.Level.Value*25)+__Armor
_Humanoid.Health = (__Player.leaderstats.Level.Value*25)+__Armor
elseif __Form == 1 then
_LevelStore:SetAsync(__UserID, __Level)
elseif __Form == 2 then
_ExperienceStore:SetAsync(__UserID, __Experience)
elseif __Form == 3 then
_GoldStore:SetAsync(__UserID, __Gold)
elseif __Form == 4 or nil then
_LevelStore:SetAsync(__UserID, __Level)
_ExperienceStore:SetAsync(__UserID, __Experience)
_GoldStore:SetAsync(__UserID, __Gold)
end
end)
end
