I try to make maxdistance billboardGui pop up

i cant figure out before it disappear, it will make a pop up/down animation
script :

local bilGui = script.Parent.Parent:WaitForChild("BillboardGui")

local tweenService = game:GetService("TweenService")
local frameCloseSpeed = 0.5
local closeEasingStyle = Enum.EasingStyle.Sine
local closeEasingDirect = Enum.EasingDirection.In

local frameOpenSpeed = 0.5
local openEasingStyle = Enum.EasingStyle.Sine
local openEasingDirect = Enum.EasingDirection.Out

if bilGui.MaxDistance <= 29.5 then
	local frame = bilGui:WaitForChild("Frame")
	if frame then
		local closeTween = tweenService:Create(
			frame,
			TweenInfo.new(
				frameCloseSpeed,
				closeEasingStyle,
				closeEasingDirect
			),
			{Size = UDim2.fromScale(0,0)}
		)
		closeTween:Play()
	else if bilGui.MaxDistance >= 29.5 then
			local frame = bilGui:WaitForChild("Frame")
			if frame then
				local openTween = tweenService:Create(
					frame,
					TweenInfo.new(
						frameOpenSpeed,
						openEasingStyle,
						openEasingDirect
					),
					{Size = UDim2.fromScale(0.6,0.6)}
				)
				openTween:Play()
			end
		end
	end
end

maxdistance is the value that controls when that billboard gui appears and disappears, so itll be the same no matter what, your best bet (and probably most laggy), is to go through all of your billboard uis, and get their parent/adorme to get the distance, and then use that.