Canvas Size [Help/Bug?]

Hello, I was wondering why when I change my canvis size VIA a script (to make auto-adjusting scrolling frames) the contents inside of my canvas either get smushed or changed…

The blue/gray boxes are all overlapping and super large… If I disable my auto-canvas changing script it looks like this. (How it should)

local index = 1

function Functions.LoadAllTeams(plr)
	for name,id in pairs(TeamData) do
		table.insert(Teams,name)
		index = index + 1
		local Clone = script.Immigrant:Clone()
		Clone.Name = name
		Clone.Text = name:upper()
		Clone.Parent = plr.PlayerGui.MainUI.Main.Teams
		Clone.Position = UDim2.new(0,0,0,(index==1 and 0) or ((index-1)*35)+(index-1))
		plr.PlayerGui.MainUI.Main.Teams.CanvasSize = UDim2.new(0,0,0, (index*35)+(index-1))
	end
end

Changed some of it up so I now use UIListLayouts and a simple script

function Functions.LoadAllTeams(plr)
	for name,id in pairs(TeamData) do
		table.insert(Teams,name)
		index = index + 1
		local Clone = script.Immigrant:Clone()
		Clone.Name = name
		Clone.Text = name:upper()
		Clone.Parent = plr.PlayerGui.MainUI.Main.Teams
		local frame = plr.PlayerGui.MainUI.Main.Teams
		frame.UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
   			frame.CanvasSize = UDim2.new(0,0,0,frame.UIListLayout.AbsoluteContentSize.Y)
		end)
	end
end

Any reason why this bug would still be going on??

After commenting out

frame.CanvasSize = UDim2.new(0,0,0,frame.UIListLayout.AbsoluteContentSize.Y)

The size was how it was. But the duplicate textbuttons I make for some reason change to scale. The original clone is in offset as well.

Values can’t just change to scale out of nowhere, so you probably have code somewhere that is changing them.

It could be that you in-line conditional statement for Clone.Position could be applying to 0, 0, 0, (index==1 and 0) instead of just (index==1 and 0). For things like that, to keep the readability up, you’d want to just make a variable for the conditional so you don’t get any weird issues.

I ended up changing the Index and used a UIListLayout.

function Functions.LoadAllTeams(plr)
	for name,id in pairs(TeamData) do
		table.insert(Teams,name)
		index = index + 1
		local Clone = script.Immigrant:Clone()
		Clone.Name = name
		Clone.Text = name:upper()
		Clone.Parent = plr.PlayerGui.MainUI.Main.Teams
		local frame = plr.PlayerGui.MainUI.Main.Teams
		frame.UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
   			frame.CanvasSize = UDim2.new(0,0,0,frame.UIListLayout.AbsoluteContentSize.Y)
		end)
	end
end

Everything including the original box that I clone is in offset.

2 Likes

I forgot I was cloning a separate gui object (which was in scale)

I’m just a spoon, sorry for this!

1 Like