Try this…
gunlistener = plr.Character.ChildAdded:Connect(function(what)
if what:IsA("Tool") then
local origtrans = Window.Transparency
repeat
Window.Transparency = 1
until Window.Transparency >= 1
Window.CanQuery = false
Window.CanCollide = false
task.wait(.2)
if what.Parent then
what.AncestryChanged:Wait()
Window.Transparency = origtrans
Window.CanQuery = true
Window.CanCollide = true
end
end```
It works but if u remove the task.wait
then it fires the ancestrychanged