Hey. I am working on a UI, but I notice when I shrink the screen as small as a phone, the UI strokes applied to the UI element stay the same size as the original screen. If you don’t understand what I mean by that, the UI stroke compared to the UI element itself is bigger than the UI element.
-- LocalScript parented to a UIStroke
local BASE_SIZE = 1200
local uiStroke = script.Parent
local initialStrokeThickness = uiStroke.Thickness
local camera = game:GetService("Workspace").CurrentCamera
local function updateStrokeThickness()
uiStroke.Thickness = initialStrokeThickness * camera.ViewportSize.X / BASE_SIZE
end
camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateStrokeThickness)
updateStrokeThickness() -- nice catch from @ItsCaelmYt :)
This code scales the stroke by the x-axis of the screen.
If you want it to scale per UI element, Exarpo has an example of how to do that.
I made it work. In the code you made above, it doesn’t call the function alone. I added updateStrokeThickness to the end of it, and it seemed to work. Is this what you meant to put or has something else happened?
The code scales the stroke by the screen size, but it needs a screen size to compare to. Base size is the screen size that corresponds to a scaling of 1 (the stroke is scaled by screen size over base size).
It’s easier to explain with an example: say you had a stroke thickness of 4. If your screen size was half of base size, the stroke thickness would be 2 (half of the set thickness). If the screen was 2400 pixels wide, the stroke thickness would become 8.
You don’t really need to change that, it’s just a constant. You want it to be about the width of a regular screen.
-- Made by @BendsSpace and edited by @ItsCaelmYt
-- Place in StarterGUI
for i, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("UIStroke") then
local BASE_SIZE = 1200
local uiStroke = v
local initialStrokeThickness = uiStroke.Thickness
local camera = game:GetService("Workspace").CurrentCamera
local function updateStrokeThickness()
uiStroke.Thickness = initialStrokeThickness * camera.ViewportSize.X / BASE_SIZE
end
camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateStrokeThickness)
updateStrokeThickness()
end
end