How to make ScrollbarThickness change depending on the device?

The ScrollBarThickness for this ScrollingFrame looks like it changes on all devices, but the problem is actually that it isn’t. It is set at 43 as that’s the X.Offset (converted from the X.Scale) of the “background” I had made for the scroll bar.

Although this could be posted on #help-and-feedback:art-design-support, I posted it here as it looks like something that could be fixed with scripts. I’d try to script it myself but I’m not very good at math.

get the size pixel size of the scrolling frame and set the bar thickness with how wide it is

EX:
local frame = script.Parent
local function ChangeScroll()
local size = frame.AbsoluteSize.X
frame.ScrollBarThickness = size/10 -- however thick you want
end
frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(ChangeScroll)
should be something like that

2 Likes

Thank you! I forgot about AbsoluteSize. Here is the finished code:

local scrollingFrame = script.Parent
local scrollbarThickness = scrollingFrame.ScrollBarThickness
local shopWindow = scrollingFrame.Parent
local scrollbarBG = shopWindow:FindFirstChild("Scrollbar Background")

local function roundUp(n, decimalPlaces)
	return math.round(n * 10^decimalPlaces) * 10^-decimalPlaces
end

scrollingFrame:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
	local size = scrollbarBG.AbsoluteSize.X
	scrollingFrame.ScrollBarThickness = roundUp(size, 0)
end)