Plugins loading before studio causing bugs

I started having this issue recently where my plugin would load in before the rest of the studio did. It relies on StarterGui:DescendantAdded(), so it runs the script before the studio has even loaded, which is causing issues.

:confused: I have tried using game.Loaded to check if the studio has loaded yet but it’s still not helping.

This bug happens 100% of the time when I turn on automatic scaling on my plugin and enter a game.


Repro Steps

Step 1: Install AutoScale plugin
Step 2: Open a studio place and go to the plugins tab
Step 3: Press settings button from AutoScale plugin
image
Step 4: Enable “Convert to Scale Size” which is a feature that relies DescendantAdded()
image
Step 5: Place some visible UI into the studio place and save the place
Step 6: Re-enter the studio place, and the UI should have grown enormously huge for some reason because its being scaled again when it detects UI being loaded into the game as new descendants.

Before (With automatic scaling feature off):

After (With automatic scaling feature on):


This bug happens in studio, I am running Windows 10.

This bug started happening when plugin installations were moved to the cloud. I suspect a result of this is that the plugin loads faster than studio loads, causing issues with DescendantAdded()

Multiple users have reported this issue with my plugin to me, and this issue is causing the UI in games to completely become enormous and game-breaking.

Thanks for reading :slight_smile:

If this happened in the last week or so, I also got a notification that one of my plugins broke. I haven’t looked into fixing it, yet, so I don’t know if it’s the same root cause.

1 Like

I have moved the post to studio bugs.

I would like to look into this. It would help if you could provide a minimal test case. Like you could post a simple-as-possible lua script that demonstrates the problem, clearly indicating what you expect to happen vs what actually happens.

1 Like

I guess specifically I want to zero in on “issue with DescendantAdded”. Give me the smallest script possible that makes the call to DescendantAdded, documenting what you expect to happen vs what actually happens.

1 Like

Sure! I will send the code soon

Here is the code to my automatic scaling feature. This script is located under a BoolValue object.

local startergui = game.StarterGui

function ToScale(guiobject)
game:GetService( 'RunService' ).RenderStepped:Wait()
local Viewport_Size

if guiobject:FindFirstAncestorWhichIsA("GuiObject") then
	Viewport_Size = guiobject:FindFirstAncestorWhichIsA("GuiObject").AbsoluteSize
else
	Viewport_Size = workspace.CurrentCamera.ViewportSize
end


local LB_Size = guiobject.AbsoluteSize
guiobject.Size = UDim2.new(LB_Size.X/Viewport_Size.X,0,LB_Size.Y/Viewport_Size.Y, 0)
end

startergui.DescendantAdded:connect(function(v)
    if game.Loaded and v:IsA("GuiObject") and not v:IsA("ScreenGui") and not v:IsA("Folder") and not v:IsA("StarterGui") and script.Parent and script.Parent.Value == true then
    --Convert to Scale
    ToScale(v)
	print("Auto Set Size to Scale")
    end 
end)

coroutine.resume(coroutine.create(function()
while wait(1) do
	if script.Parent then
	if plugin:GetSetting("Active") == true then
		script.Parent.Value = true
	else
		script.Parent.Value = false
	end
	end
end
end))

It is supposed to automatically set size of any GUIObject you insert into startergui when studio has loaded and you are creating UI to Scale, it is not supposed to detect the GUI being loaded into studio.

1 Like

Thanks.
Could I ask for an even more reduced script, and even more explicit description of expected vs actual behavior?

E.g. just a one-script-file plugin that does

local startergui = game.StarterGui
startergui.DescendantAdded:connect(function(v)
<something in here?>
end)

local startergui = game.StarterGui

function ToScale(v)
game:GetService( 'RunService' ).RenderStepped:Wait()
local Viewport_Size

if v:FindFirstAncestorWhichIsA("GuiObject") then
	Viewport_Size = v:FindFirstAncestorWhichIsA("GuiObject").AbsoluteSize
else
	Viewport_Size = workspace.CurrentCamera.ViewportSize
end

local LB_Size = guiobject.AbsoluteSize
guiobject.Size = UDim2.new(LB_Size.X/Viewport_Size.X,0,LB_Size.Y/Viewport_Size.Y, 0)
end

startergui.DescendantAdded:connect(function(v)
    if game.Loaded then
    --Convert to Scale
    ToScale(v)
    end 
end)

Expected Behaviour: Any gui object inserted manually after studio has loaded into StarterGUI is automatically converted to Scale size, so the default size is set to Scale.

Actual Behaviour: GUI inserted by studio while the game is loading is also converted to scale which is causing GUI to grow massive.

A post was merged into an existing topic: UI Editor not appearing