How to scale UI Strokes across All Devices

Hello!

My name is Caelm, and I am going to teach you how you can scale UIStrokes in these three easy steps! By using this tutorial, you can turn unintentional large UIStrokes on smaller devices into UIStrokes that look exactly the same on different screens!

Step One

Open Explorer, and find StarterGui. Add a ScreenGui into StarterGui. You can name this ScreenGui whatever you want, but I’m going to name mine UIStrokeScaler.

image

Step Two

Inside your ScreenGui, you want to add a LocalScript. You can name this LocalScript whatever you want as well, but I am going to name mine Main.

image

Step Three

Open your LocalScript, and replace any code that has already been written with the following code:

-- Made by @ItsCaelmYt

for i, v in pairs(script.Parent.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

This code will get the current device’s screen resolution, and re-calculate the any UIStroke in StarterGui, so that the UIStroke looks the same across all devices.

Additional Information

This will not scale UIStrokes when not playing your experience in Studio. However, if you play your experience in Studio while emulating your device, the UIStrokes will scale.

Sometimes, the UIStrokes may not be perfect, but improved.

If you have any questions, reply below! Thanks!

28 Likes

This was very helpful. Thank you!

4 Likes

Would be useful in the future, for mobile-support on my games. Thanks for sharing this!

3 Likes

Hey there, amazing script, but im just wondering about scaling the ui strokes when players adjust their tab size on pc.