Neither AbsolutePosition nor Position being updated on gui position change

Hello, could someone help me fix this issue with this script!

  1. What do you want to achieve? I want to have a gui with a scrolling bar that prints “successful” if the bar is on the target when the button is pressed.

  2. What is the issue? AbsolutePosition and Position are only updated ONCE (on the first change of location), and no other properties of the GUI seem to have any information about the GUI’s current location on screen.

  3. What solutions have you tried so far? I have tried both using Position and AbsolutePosition as checks for the target’s position, but neither have worked.

Script:

local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ScreenGui

local frame = gui.BarFrame
local bar = frame.Bar
local button = frame.PictureButton
local target = frame.Target
local dp_accuracy = 2

--print(tostring(target.Size.X.Offset))
--print(tostring(target.Position.X.Scale))
--print(tostring(target.Size.X.Offset / 50))

--10 pixels = 0.02

while true do
	wait(1)
	
	--Range = 24
	target.Position = UDim2.new(0, Random.new():NextInteger(1, 24) * 20, 0, 0)
	
	--Get position of target
	local scale = math.floor(target.AbsolutePosition.X * 10 ^ dp_accuracy) / 10 ^ dp_accuracy

	--Get boundaries of target
	local min_distance = math.floor((scale - target.Size.X.Offset) * 10 ^ dp_accuracy) / 10 ^ dp_accuracy
	local max_distance = math.floor((scale + target.Size.X.Offset) * 10 ^ dp_accuracy) / 10 ^ dp_accuracy
	
	button.MouseButton1Click:Connect(function()
		local bar_pos = bar.AbsolutePosition.X
		print(tostring(bar_pos))
		print(tostring(min_distance))
		print(tostring(max_distance))
		if bar_pos >= min_distance and bar_pos <= max_distance then
			print("successful!")
		else
			print("broken")
		end
	end)
	
	
	--Repeat until the bar is at the end of the frame
	while bar.AbsolutePosition.X <= 760 do
		wait(0.1)
		bar.Position += UDim2.new(0, 20, 0, 0)
	end
	
	bar.Position -= UDim2.new(0, 500, 0, 0)
end

Hierarchy of objects:
image

Actual GUI in game:

Thanks for reading this post!