So i have this anticheat thing that is supposed to delete gui's that were randomly added to playergui but for some reason i got this warning:
Something unexpectedly tried to set the parent of ScreenGui to NULL while trying to set the parent of ScreenGui. Current parent is PlayerGui. (x58) - Studio
Script:
while wait(0.3) do game.Players.LocalPlayer.PlayerGui.ChildAdded:Connect(function(child) if child.ClassName == "ScreenGui" then child:Remove() end end) end
You should wait a few seconds before deleting the Gui.
I recommend using Instance:Destroy()
instead of Instance:Remove()
because it only parents it to nil, unlike Instance:Destroy()
which locks all properties and sets it to nil, disconnects all events, and sets the parent to nil. This also applies to its children.
Also I don't recommend connecting an event in a loop, the loop is really unnecessary.
local Players = game:GetService("Players") local Debris = game:GetService("Debris") local Player = Players.LocalPlayer local PlayerGui = Player:WaitForChild("PlayerGui") PlayerGui.ChildAdded:Connect(function(child) if child:IsA("ScreenGui") then -- similar to `if child.ClassName == "ScreenGui" then` Debris:AddItem(child, 0.3) -- similar to `task.wait(0.3); child:Destroy()` end end)