Gui canvasSize not scaling properly

image

module.SetCards = function(Player , Platform)
	local cardService = require(script.Parent.CardService)
	print(module.TemporaryCache[Player.UserId])

	local pos = 0
	for i = 1,7 do
		
		local randomcardval = math.random(1 , #module.TemporaryCache[Player.UserId])
		local uncard = module.TemporaryCache[Player.UserId][randomcardval]
		local card = cardService.Unserialize(uncard)
		table.remove( module.TemporaryCache[Player.UserId] , randomcardval)
		card.Parent = Platform.Hand.HandGui.ScrollingFrame
		card.Position = UDim2.new(pos,0,0,0)
		pos = #Platform.Hand.HandGui.ScrollingFrame:GetChildren() * 0.2
		Platform.Hand.HandGui.ScrollingFrame.CanvasSize = UDim2.new(pos,0,1,0)
	end
	print(module.TemporaryCache[Player.UserId])
end

The card’s size is 0.2 in scale, so the scrollingGui’s canvasSize should be exact.

1 Like

Alternate suggestion: use AbsoluteContentSize to adjust the CanvasSize. Do this after the loop.

-- Please oh please make a variable for the ScrollingFrame, I see that you
-- don't have one and rewrite this same line 3+ times.
local scrollingFrame = Platform.Hand.HandGui.ScrollingFrame
-- Anyway, the actual code.
local absoluteContentSize = scrollingFrame.AbsoluteContentSize
scrollingFrame.CanvasSize = UDim2.new(0, absoluteContentSize.X, 1, 0)

Are you sure that’s a property of scrollingframe?
image

Oops, no it’s not. AbsoluteContentSize is a property of UI layouts. For some reason I assumed you were using one (you really should in this case, it would handle the positioning and padding automatically) and also incorrectly stated that it comes from ScrollingFrame. If you have a UIListLayout it will have AbsoluteContentSize that you can use to control the sizing of your frame.

Do you have one…?

1 Like

no, but it makes sense gonna do that brb.

Ok now how do i set the canvasSize to the AbsoluteConstentSize