Script to adjust UI doesn't work accurately when sharply resizing window size

Hello!

I’m currently working on handling my game’s inventory however I am experiencing an issue where if the user sharply changes their screen size, the script I made to adjust the cell size doesn’t work properly. Not sure how else to explain it but here’s a video:

The goal is to have an unlimited amount of columns but only 5 rows but the cells should be perfectly square.

Script:

local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')

local player = players.LocalPlayer

local playerData = player:WaitForChild('PlayerData')
local inventory = playerData:WaitForChild('Inventory')
local inventoryItems = inventory:WaitForChild('Items')

local items = replicatedStorage:WaitForChild('Items')

local scrollingFrame = script.Parent.ItemFrameHolder.ScrollingFrame
local uiGridLayout = script.Parent.ItemFrameHolder.ScrollingFrame.UIGridLayout

uiGridLayout.CellSize = UDim2.new(0, scrollingFrame.AbsoluteSize.X / 5, 0,  scrollingFrame.AbsoluteSize.X / 5)

workspace.CurrentCamera:GetPropertyChangedSignal('ViewportSize'):Connect(function()
    uiGridLayout.CellSize = UDim2.new(0, scrollingFrame.AbsoluteSize.X / 5, 0,  scrollingFrame.AbsoluteSize.X / 5)
end)

Script:

Maybe this will help unless you already saw it.

Thanks for that.

The problem is that it doesn’t force a specific amount of cells which I want to do. I want it to be locked at 0.2 of the ScrollingFrame’s x AbsoluteSize property. If I use an AspectRatioConstraint, it creates a large gap between the cells vertically.

I also want to avoid these large white bars at the edge.
Capture d’écran, le 2021-01-24 à 02.54.25

I will see if I can help you tomorrow since it is late where I live.

1 Like

Ended up fixing it by binding to renderstep.