Leveling system, the bar frame of the leveling Gui not working

  1. What I want to achieve?
    I want when a player’s exp changes the GUI bar frame to change too.

  2. What is the issue?
    when the exp changes, the bar frame doesn’t want to move.
    https://streamable.com/7206ru

  3. What solutions I have tried so far?
    I tried to change my script but still didn’t work.

local stat = DataSaveService:GetDataStore("Stats")
local barframe = game.StarterGui.LevelGui.Frame.barframe
local defaultValue = 100

game.Players.PlayerAdded:Connect(function(plr)
	local status = Instance.new("Folder", plr)
	status.Name = "leaderstats"
	local exp = Instance.new("IntValue", status)
	exp.Name = "Exp"
	local level = Instance.new("IntValue", status) 
	level.Name = "Level"
	local expNeeded = Instance.new("IntValue", status)
	expNeeded.Name = "ExpNeeded"
	
	local exps
	local levels
	local expNeededs
	
	local success, errormsg = pcall(function()
		exps = stat:GetAsync(plr.UserId.."-Exp")
		levels = stat:GetAsync(plr.UserId.."-Level")
		expNeededs = stat:GetAsync(plr.UserId.."-ExpNeeded")
	end)
	if success then
		exp.Value = exps
		level.Value = levels
		expNeeded.Value = expNeededs
		print("The player data has been saved") 
	else
		print("player data load error") 
		warn(errormsg) 
	end
	
	spawn(function() 
		while wait() do
			if exp.Value >= expNeeded.Value then
				barframe.Size = UDim2.new(exp.Value/expNeeded.Value, 0, 1, 0)
				exp.Value = exp.Value - expNeeded.Value
				level.Value = level.Value + 1
				expNeeded.Value = expNeeded.Value + 87.5 * 2
				barframe.Size = UDim2.new(exp.Value/expNeeded.Value, 0, 1, 0)
			else
				barframe.Size = UDim2.new(exp.Value/expNeeded.Value, 0, 1, 0)
				exp.Value = exp.Value
				level.Value = level.Value
				expNeeded.Value = expNeeded.Value
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormsg = pcall(function()
		stat:SetAsync(plr.UserId.."-Level", plr.leaderstats.Level.Value)
		stat:SetAsync(plr.UserId.."-Exp", plr.leaderstats.Exp.Value)
		stat:SetAsync(plr.UserId.."-ExpNeeded", plr.leaderstats.ExpNeeded.Value)
	end)
	if success then
		print("Player data got saved")
	else
		print("Failed at saving data")
		warn(errormsg)
	end
end)
1 Like

Using TweenService might help.

1 Like

so you are saying that it’s better to use TweenService than Size?

TweenService has it’s own size property, did you even read the article?

Part:TweenSize(Udim2.new(),) --Then write your properties. Sine might be a good easing style for what you're aiming for.

no, I didn’t, I will check it.
ok thanks

1 Like