Problem with scaling UIStroke

I have a problem with UIStroke scaling. I have script which changes their size depended on viewport size. The problem is that UIStrokes which are in ScreenGuis which weren’t set to ResetOnRespawn are getting bigger every time a player resets.

Scripts:

Local Script (game.StarterGui):

local UIStrokeResponder = script.UIStrokeResponder
 
 for _, descendant in game:GetDescendants() do
	if descendant:IsA("UIStroke") then 
		local UIStrokeResponderClone = UIStrokeResponder:Clone()
		UIStrokeResponderClone.Enabled = true
		UIStrokeResponderClone.Parent = descendant
	end
 end

Local Script (game.StarterGui.UIStrokeInserter(It’s child of the first script)):

local correctionFactor = 1500 -- Factor is an estimation for responsiveness to normal sizes. Can make higher if want THINNER strokes and lower if want THICKER strokes
 local UIStroke = script.Parent
 local thickness = UIStroke.Thickness

 UIStroke.Thickness = workspace.CurrentCamera.ViewportSize.Magnitude/correctionFactor * thickness

 workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()

	UIStroke.Thickness = workspace.CurrentCamera.ViewportSize.Magnitude/correctionFactor * thickness
 end)
1 Like

You could just add an Attribute for UIStrokes you have checked already, you could use tags that are automatically on all UI Strokes that this applies to and remove them once done(What I would recommend), or just move around the code so it doesn’t run every time the player dies.

You could try having your code that adds the scaling script give each UIStroke a base thickness value so that the scaling scripts can’t be working off of different base thicknesses.

local UIStrokeResponder = script.UIStrokeResponder
 
 for _, descendant in game:GetDescendants() do
	if descendant:IsA("UIStroke") then 
		local UIStrokeResponderClone = UIStrokeResponder:Clone()
		descendant:SetAttribute("BaseThickness", descendant.Thickness)
		UIStrokeResponderClone.Enabled = true
		UIStrokeResponderClone.Parent = descendant
	end
 end
local correctionFactor = 1500 -- Factor is an estimation for responsiveness to normal sizes. Can make higher if want THINNER strokes and lower if want THICKER strokes
local UIStroke = script.Parent
local thickness = UIStroke:GetAttribute("BaseThickness")

UIStroke.Thickness = workspace.CurrentCamera.ViewportSize.Magnitude/correctionFactor * thickness

workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
	UIStroke.Thickness = workspace.CurrentCamera.ViewportSize.Magnitude/correctionFactor * thickness
end)

I added there to add responder if it’s not child of a UIStroke.

1 Like

That also works (probably a better solution anyways since it solves the core problem: multiple conflicting scripts).