'TweenSize()' goes outside frame and not within

Hello! So I have this level gui. My problem is that the bar goes outside the frame. Here’s my local script in the gui:

local Player = game.Players.LocalPlayer

local XP = Player.XP
local RequiredXP = Player.RequiredXP

script.Parent.XPBar:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0,1,0))

XP.Changed:Connect(function(changed)
	if changed then
		script.Parent.XPBar:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0,1,0))
	end
	
end)

while wait() do
	script.Parent.XPLabel.Text = XP.Value.."/"..RequiredXP.Value
end

And here’s a part of a leaderstats and data store script i used for my level gui:

	local level = Instance.new("NumberValue")
	level.Name = "Level"
	level.Parent = leaderstats
	level.Value = 1

	local XP = Instance.new("NumberValue")
	XP.Name = "XP"
	XP.Parent = player
	XP.Value = 0
	
	local RequiredXP = Instance.new("NumberValue", player)
	RequiredXP.Name = "RequiredXP"
	RequiredXP.Value = level.Value*100

XP.Changed:Connect(function(changed)
		
		if XP.Value >= RequiredXP.Value or XP.Value == RequiredXP.Value then
			XP.Value = 0
			
			level.Value += 1
			RequiredXP.Value = level.Value*100
			
		end
	end)

Somehow, I’m not getting any errors or warnings from it but nothing happens. Is there any solution to this?

Changed is referencing the new value of XP.

Also try this,
Instead of this:

Try:

script.Parent.XPBar:TweenSize(UDim2.new((XP.Value/RequiredXP.Value)/100, 0,1,0))

Last thing,
Remove the while wait loop and move

Into the changed function

Try this for the local script:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local XP = LocalPlayer:WaitForChild("XP")
local RequiredXP = LocalPlayer:WaitForChild("RequiredXP")
local Frame = script.Parent

--//Functions
Frame:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0, 1, 0))

RequiredXP:GetPropertyChangedSignal("Value"):Connect(function()
	Frame.XPLabel.Text = XP.Value.. "/" ..RequiredXP.Value
	Frame:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0, 1, 0))
end)

There is virtually no difference in your script other than you removing the while wait do loop and moving the line into the changed event, aswell as doing some longer typing (

Which is the same as RequiredXP.Changed

BTW, not sure if it was in purpose or not but, he used XP.Changed not RequiredXP.Changed

I used RequiredXP:GetPropertyChangedSignal(“Value”) because when the XP changes, it takes a split second for the RequiredXP to change so it might put the wrong RequiredXP if we use XP.Changed instead of RequiredXP.Changed

1 Like

I also used GetPropertyChangedSignal(“Value”) as .Changed actually detects almost every change (such as name changes, not just the value changing).

Well here I go again,

This would be true for any case other than an “ValueInstance” (ex. StringValue, IntValue, etc), there is a special rule for “ValueInstances” that the .Changed method is only for .Value

Ok, so I followed what you said. Sadly it didn’t work; the bar got smaller when I tested it by adding 100 XP.

Okay, what if you do:
script.Parent.XPBar:TweenSize(UDim2.new(XP.Value/(RequiredXP.Value/100), 0,1,0))

2 Likes

That didn’t work too; it only took 1 XP out of 100 to take up the entire space.

Alright, go back to your original, and can you show us a video of you testing it

Don’t think this will make a difference but just remove that as it’s unnecessary anyways because you used >=

1 Like

Well, it didn’t work with it anyway. In fact, I only added the or XP.Value == RequiredXP.Value to see if it made a difference.

Here’s the video I got it from:

I followed all the instructions so I don’t know what’s going on with my level bar. :confused: (it used to work)