Easily scale all UIStrokes with one script

Ever tested your game on mobile and realized how much thicker your UI strokes were?
I did too, and I wanted a quick solution!

So I made this quick script for my games, and I hope it’s useful for you all too!
Code:


local BASE_SIZE = 1885 -- set this to the x of your default viewport size
-- use this command in the command bar to figure out what yours is: print(workspace.Camera.ViewportSize.X)

local initalThicknesses = {}
local camera = game:GetService("Workspace").CurrentCamera

-- set inital thicknesses
for _,obj in pairs(game.Players.LocalPlayer.PlayerGui:GetDescendants()) do
    if obj:IsA('UIStroke') then
        initalThicknesses[obj] = obj.Thickness
        obj.Destroying:Once(function()
            initalThicknesses[obj] = nil
        end)
    end
end

local function updateStrokeThickness(uistroke)
    uistroke.Thickness = initalThicknesses[uistroke] * camera.ViewportSize.X / BASE_SIZE
end


local function updateThicknesses()
    for _,obj in pairs(game.Players.LocalPlayer.PlayerGui:GetDescendants()) do
        if obj:IsA('UIStroke') then
            updateStrokeThickness(obj)
        end 
    end
end

local function newItem()
    for _,obj in pairs(game.Players.LocalPlayer.PlayerGui:GetDescendants()) do
        if obj:IsA('UIStroke') then
            if initalThicknesses[obj] == nil then
                initalThicknesses[obj] = obj.Thickness
                obj.Destroying:Once(function()
                    initalThicknesses[obj] = nil
                end)
            end
    
        end
    end
    
    updateThicknesses()
end

camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateThicknesses)
game.Players.LocalPlayer.PlayerGui.DescendantAdded:Connect(newItem)

updateThicknesses() 
3 Likes