DescendantAdded fires whenever i move the guiobject

Hello, I’m trying to achieve an autoscale size and positioning, meaning of this is whenever you add a frame to a screen GUI inside a frame or anything instead of it starting as offset on size or position it gets automatically converted to scale.

Note – This is a plugin

But my issue is whenever I move the GUI object it fires like a hundred times. here is my code.

game.DescendantAdded:Connect(function(descendant)
    if descendant:IsA("GuiObject") and AutoSS then
        print("Test")
        game.Selection:Add({descendant})
        AutoScale.SetSize("Scale") 
        game.Selection:Remove({descendant})
    end
    if descendant:IsA("GuiObject") and AutoPS then
        print("Test")
        game.Selection:Add({descendant})
        AutoScale.SetPos("Scale")
        game.Selection:Remove({descendant})
    end
end)

https://cdn.discordapp.com/attachments/1012702781997600818/1012803637933789214/2022-08-26_21-18-45.mp4?size=4096
Doing childadded I could only do this for like startergui and not inside screenguis

1 Like

How about print(descendant) to see what is getting added that fires the function and bypassing it?

ktPQRPL.png (1921×1033) (imgur.com)
1K0d39v.png (1377×260) (imgur.com)

this prints imagelabel for some weird reason even tho its a frame.

I forgot to add a video of what happens, but I edited the video sadly it will download a video since I don’t know how I would make it a embed

Does the GUI get highlighted when you move it causing the addition of those .png images?

Hello, i dont really understand what you meant by highlighted?
if you talking about the resize buttons when you select a frame or something they move with the frame but it is very laggy and is going behind.

I believe the imagelabel and the dropshadow stuff are the things that come when you click on the frame “as you said” highlighted I think

When you move the GUI does it change at all, like when you mouse over some items the images goes lighter or darker or the border changes (highlighting it). That would probably add a descendant.

If so can you not just put a line after like if descendant == those items then end

1 Like

Hello, again, it might be the reason of the borders when you select a frame as you said.

But I don’t understand of the descendant? did you mean like if descendant == frame or descendant == textabel.

1 Like

I fixed it, instead of doing a game.DescendantAdded I would choose workspace and startergui since if I only do game it will also detect coregui and the Roblox highlight when you select a GUI object to like resize will get detected this is why I get this error.

1 Like

You were checking for
game.DescendantAdded:Connect(function(descendant)
Your complaint was that that function is firing multiple times.
My comment was to check what descendant was being added.

I didn’t notice you were using game.DescendantAdded. If I did I would have said you should change that to check the Descendant of only the item you want to have the script check for.