Help with :GetPropertyChangedSignal

So I have a :GetPropertyChangedSignal in my game, the property it is tracking is the visible property for GuiObjects, Now, problem is that I change the visible property after the signal is fired, which makes it go in an infinite loop, Idk if this is normal (I thought I saw somewhere it isnt)

If not, how can I work around this? Its kinda annoying (it crashes the whole game)

local function VisibleChanged(Frame:Frame)
	local Info = UIStorage:Find(Frame)
	
	if not Info then
		Info = {
			Size = Frame.Size,
			Position = Frame.Position,
		}
		
		Info = UIStorage:Store(Frame,Info)
	end
	
	local Visible = Frame.Visible
	
	if Visible then
		Frame.Visible = false
		Frame.Size = UDim2.new(0,0,Frame.Size.Y.Scale,Frame.Size.Y.Offset)
		local Tween = TweenService:Create(Frame,OpenAnimationInfo,Info.Item.Size)
		
		Frame.Visible = true
		Tween:Play(); Tween.Completed:Wait(); Tween:Destroy()
	else
		Frame.Visible = true
		local Size = UDim2.new(0,0,Frame.Size.Y.Scale,Frame.Size.Y.Offset)
		local Tween = TweenService:Create(Frame,OpenAnimationInfo,Size)

		Tween:Play(); Tween.Completed:Wait(); Tween:Destroy(); Frame.Visible = false
	end
end

-- // Main //

function Module:SetUI(PassedUI:ScreenGui)
	UI = PassedUI
	
	for _, Frame:Frame in UI:GetDescendants() do
		if Frame:GetAttribute(AnimKey) ~= nil and Module.AnimsEnabled then
			print('Enabled')
			Frame:GetPropertyChangedSignal('Visible'):Connect(VisibleChanged,Frame)
		end
	end

	UI.DescendantAdded:Connect(function(Frame:Frame)
		if Frame:GetAttribute(AnimKey) ~= nil and Module.AnimsEnabled then
			Frame:GetPropertyChangedSignal('Visible'):Connect(VisibleChanged,Frame)
		end
	end)
end

It’s probably because in the VisibleChanged function, you are setting the “Visible” property, which makes getpropertychangedsignal fire again, and it goes in an infinite loop.

Didnt I say that? Oops.

Yeah thats the problem I’m facing, it goes in an infinite loop, uh Idk what else to add

1 Like

Just a guess here from what you’re saying…

When it changes the visibility it is self trigging again… So after the trigger you need to check the state then do what you doing.

if then return … kinda thing

Hmm yeah thats smart lol. Lemme go do that

Honestly I have no idea why I didnt think of this. Sometimes the brain dont click.

Thanks!

1 Like

Ya I hit this one too … :rofl: made me double guess for a bit also.

1 Like