How to detect if ScreenGui == nil

Hello!
I made a script so that if the GUI was in PlayerGui, the script would stop, and play after the GUI was gone.

But it doesn’t work for some reason >:(

What other ways are there? Or tell me why it’s not working for me

		-- CHECK IF ALREADY HAVE GUI
		local Check = Player.PlayerGui:FindFirstChild("NewItemHolder")
		if Check then
			repeat task.wait()
				print(tick())
			until not Player.PlayerGui:FindFirstChild("NewItemHolder")
		end
		-- CHECK IF ALREADY HAVE GUI

2 Likes

The script is located in the module script

1 Like

You may want to do this:

repeat wait() until Player.PlayerGui:FindFirstChild("GUI_NAME") == nil
1 Like

Dont worked too >:(
idk, maybe need another way?

1 Like

You told that its a module script, Can you share whole module script and the other script requiring it?

1 Like

The cycle still repeats even though the gui is already gone :frowning:

1 Like

Uhh, he have many many lines of code

i can give u full module

local SS = game:GetService("ServerStorage")

local _Itemmodule = {}

function _Itemmodule.Add(Player,ItemName,RareType,Action)
	
	local Tools = SS:WaitForChild("Assets")

	local _CurrentFolder = Tools:FindFirstChild(Action)
	local _RareFolder =_CurrentFolder:FindFirstChild(RareType)
	local _CurrentItem = _RareFolder:FindFirstChild(RareType.." "..ItemName)
	
	if _CurrentItem then
		
		_CurrentItem.Parent = Player.Backpack
		
	end
	
end

function _Itemmodule.Message(Player,Item,RareType)
	
	local Models = SS:WaitForChild("Assets"):WaitForChild("Models")
	local _CurrentModel = Models:FindFirstChild(RareType.." "..Item)
	
	local _CloneGui = script:WaitForChild("NewItemHolder"):Clone()
	local _RemoteEvent = _CloneGui:WaitForChild("Showcase")
	
	if _CurrentModel then
		
		-- CHECK IF ALREADY HAVE GUI
		local Check = Player.PlayerGui:FindFirstChild("NewItemHolder")
		if Check then
			repeat wait() print(tick()) until Player.PlayerGui:FindFirstChild("NewItemHolder") == nil
		end
		-- CHECK IF ALREADY HAVE GUI
		
		-- code:
		
		for i,v in ipairs(_CloneGui:GetDescendants()) do
			if v:IsA("Script") or v:IsA("LocalScript") then
				if v.Name ~= "Ignore" then
					v.Enabled = true
				end
			end
		end
		
		task.wait()
		
        _CloneGui.Parent = Player.PlayerGui
        _CurrentModel.Parent = _CloneGui.Holder.ViewportFrame.WorldModel
		
		_RemoteEvent:FireClient(Player,_CurrentModel.Name,RareType)
		
	else
		warn("Item not found")
	end
	
end

return _Itemmodule
1 Like

I just need other ways to verify that the script has stopped and continued when the object is gone

1 Like

Check the PlayerGUI folder of player, maybe one NewItemHolder is being deleted when other is created?

1 Like

Try Check.Destroying:Wait(), Instead of repeating a task.wait()

1 Like

Remove the:
if Check then (i.e. remove the if statement, just run the repeat loop)
To debug, add print(“Yippie! Escaped!”) after the repeat loop.

1 Like

Maybe a video will help you? :slight_smile:
When Tick number is written in the console, it means that a check is in progress. (when the GUI in PlayerGui is removed).

In the video I show that the GUI is not deleted prematurely, but only when I click on a button in the GUI

1 Like

Also intead of printing(tick()), Print “Player.PlayerGui:FindFirstChild(“NewItemHolder”)”

1 Like

u mean this?

1 Like

Pardon my bad English >:o
I use a translator

1 Like

no this:

repeat wait() print(Player.PlayerGui:FindFirstChild("NewItemHolder")) until Player.PlayerGui:FindFirstChild("NewItemHolder") == nil
print("Yippie! Escaped!")
1 Like

too dont work :frowning:
idkkk why its dont woork!

1 Like

What does it print when executing new code?

1 Like

Cyclic text

print(Player.PlayerGui:FindFirstChild(“NewItemHolder”)

And he’s not stopping

1 Like

Dont work :((
i really idk why it happened

1 Like