AbsoluteSize.Y is not returning an updated size

Alright. The title says most of it but to clarify, gui.AbsoluteSize.Y is not returning the same value as shown in the Properties window. I want to achieve an automatic sizing container for a few frames.
I have set AutomaticSize to Y and the Size to 0 on the Y axis on all of the Frames and TextLabels in the container. If this does matter, I am creating a clone of another object, then adding a transition into the screen.

With no text in the text boxes, the size is automatically set to 97 for the container. With 2 lines, the absolute size is 115, however, the script returns 97 as if there was default text. Running a separate script after the creation of the GUI returns the valid Absolute Value.

This is the script on the client side: Note: the gui variable is a Frame in which the clones and templates are stored.

spawn(function ()
	local alert = gui["Notice Open Template"]:Clone()
	alert.Name = "Notice Open Clone"
	alert.Parent = gui
	alert.Visible = true
	alert.Container.Core.Title.Text = "Personal Message from " .. data.Player.Name
	alert.Container.Core.Body.TextBox.Text = data.Content

	alert.Size = UDim2.new(0, 500, 0, alert.Container.AbsoluteSize.Y)
	
	for i,v in ipairs(gui:GetChildren()) do
		if v.Name == "Notice Open Clone" then
			v.LayoutOrder += 1
			v.Container:TweenPosition(UDim2.new(0, 0, -(v.LayoutOrder - 1), -(v.LayoutOrder - 1) * 10), 'Out', 'Quint', 0.3, true)
		end
	end
	
	alert.Size = UDim2.new(0, 500, 0, alert.Container.AbsoluteSize.Y)
end)

This is my first forum topic post, so please tell me what I should keep in mind for future posts. Thank you in advance for the help!

It sounds like there may be an issue with the way you are accessing the AbsoluteSize property of your container. One possible reason for the discrepancy you’re seeing is that the container’s AbsoluteSize property may not have updated to reflect the actual size of the container, before you accessed it in your script.

You could try adding a brief pause or delay in your script, between the creation of the alert and the calculation of the container’s size, to give the AbsoluteSize property time to update.

Alternatively, you could use a RenderStepped connection to continuously check for changes in the container’s size, and update the alert’s size accordingly.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.