I was wondering how I can get the remaining xp from someone when they level up. I have a fully functional level system with ui and I was wondering how I can add the remaining xp. For example if someone was level 1 and they got 100k xp it would go to level 500 or something, but for me it goes to level 2.
Here is the server code:
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local XP = Instance.new("IntValue", ls)
XP.Name = "XP"
XP.Value = 0
local MaxXP = Instance.new("IntValue", plr)
MaxXP.Name = "MaxXP"
MaxXP.Value = 100
local Level = Instance.new("IntValue", ls)
Level.Name = "Level"
Level.Value = 1
XP.Changed:Connect(function(val)
if XP.Value >= MaxXP.Value then
MaxXP.Value *= 1.25
Level.Value += 1
XP.Value = 0
end
end)
end)
and here is the client code:
local TS = game:GetService("TweenService")
local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local plr = game.Players.LocalPlayer
local leaderstats = plr:WaitForChild("leaderstats")
local XP = leaderstats:WaitForChild("XP")
local Level = leaderstats:WaitForChild("Level")
local function changed()
local fr = (XP.Value / (Level.Value * 100))
TS:Create(XpBar, info, {Size = UDim2.fromScale(fr, 1)}):Play()
end
XP.Changed:Connect(changed)
Level.Changed:Connect(changed)
Any help would be appreciated!