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…
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
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.