Auto Stroke Scale Script

Hi I’m a modeler Gold_Octopus.
I don’t know how to script well, but I have a situation I need,
so I made this script through Chat GPT 4o!

This script works when the user join and the scale changes.

It might not be perfect because it’s an AI made script.
If you have a better idea or a better fix, please let me know in the comments!

--This script is made with AI Chat GPT 4o
--It may not be perfect.
-- LocalScript in StarterGUI

local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local camera = workspace.CurrentCamera

-- Table to store the initial thickness of each UIStroke
local initialThicknesses = {}

-- Function to initialize the initialThicknesses table
local function initializeThicknesses()
	for _, guiObject in ipairs(PlayerGui:GetDescendants()) do
		if guiObject:IsA("UIStroke") then
			initialThicknesses[guiObject] = guiObject.Thickness * 1.4
			guiObject.Thickness = guiObject.Thickness * 1.4 -- Set the initial thickness to 1.4x
		end
	end
end

-- Function to update the stroke thickness based on screen size
local function updateStrokeThickness()
	local screenWidth = camera.ViewportSize.X
	local screenHeight = camera.ViewportSize.Y

	-- Check if the screen size has changed
	if screenWidth ~= previousScreenWidth or screenHeight ~= previousScreenHeight then
		local scaleFactor = math.min(screenWidth, screenHeight) / 1000 -- Adjust based on your needs

		for guiObject, initialThickness in pairs(initialThicknesses) do
			if guiObject.Parent then -- Ensure the GUI object still exists
				guiObject.Thickness = initialThickness * scaleFactor -- Scale the initial thickness
			end
		end

		-- Update the previous screen size
		previousScreenWidth = screenWidth
		previousScreenHeight = screenHeight
	end
end

-- Store the previous screen size
local previousScreenWidth = camera.ViewportSize.X
local previousScreenHeight = camera.ViewportSize.Y

-- Initialize the initial thickness values
initializeThicknesses()

-- Connect the function to RenderStepped to continuously check for screen size changes
RunService.RenderStepped:Connect(updateStrokeThickness)

-- Initial call to set stroke thickness
updateStrokeThickness()

5 Likes