How do you make a GUI stop appearing?

Hello everyone. I recently started making a self check-in and ran into a problem. I made it so when you step on a specific part, a GUI pops up and then gives you a tool. The problem is, if you keep touching the part the GUI keeps popping up. I do not want to use debounce because that would cause everyone not to be able to use the GUI and not just the one person. How do I make the script so it searches through the players backpack and if it finds a certain tool, it does not allow the GUI to pop up? Thanks.

Script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = false
local Values = script.Parent.Values
local BusinessClassName = Values.BusinessClassName.Value
local BusinessClassTicket = Values.BusinessClassTicket
local BusinessRank = Values.BusinessRank.Value
local Class3 = Values.Class3.Value
local EconomyClassName = Values.EconomyClassName.Value
local EconomyClassTicket = Values.EconomyClassTicket
local EconomyRank = Values.EconomyRank.Value
local FirstClassName = Values.FirstClassName.Value
local FirstClassTicket = Values.FirstClassTicket
local FirstClassRank = Values.FirstClassRank.Value
local InvestorClassName = Values.InvestorClassName.Value
local InvestorClassTicket = Values.InvestorClassTicket
local InvestorRank = Values.InvestorRank.Value
local groupID = Values.groupID.Value
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = game.ReplicatedStorage



local Brick = script.Parent.SCIParts.Touch

Brick.Touched:Connect(function(hit)
	if debounce then
		return
	end

	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			debounce = true
			local Gui = game.ReplicatedStorage:WaitForChild("LoadingGUI")
			local GuiClone = Gui:Clone()
			GuiClone.Parent = Player:WaitForChild("PlayerGui")
			local rank = Player:GetRankInGroup(groupID)
			Player:WaitForChild("Backpack")
			local ticket = nil
			if rank == EconomyRank then
				ticket = ReplicatedStorage:WaitForChild(EconomyClassTicket.Value)
			elseif rank == BusinessRank  then
				ticket = ReplicatedStorage:WaitForChild(BusinessClassTicket.Value)
			elseif Class3 == false then
				if rank == FirstClassRank then
					ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
				elseif rank >= InvestorRank then
					ticket = ReplicatedStorage:WaitForChild(InvestorClassTicket.Value)	
				end
			elseif rank >= FirstClassRank then
				ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
			end 
			if ticket then
				local alreadyHasTicket = Player.Backpack:FindFirstChild( ticket.Name ) or Player.Character:FindFirstChild( ticket.Name )
				if not alreadyHasTicket then
					ticket:Clone().Parent = Player.Backpack
				end 
			end 
			wait(5)
			debounce = false

		end 

	end 

end) 
1 Like

You can use tables for debounces on server scripts. This is an example:

local playerDebounces = {}

local function enableObject(player)
    if not playerDebounces[player] then
        playerDebounces[player] = true

        wait(3)

        playerDebounces[player] = false
    end
end

Do you mean stop appearing in studio or in game? I belive you can use debounce. In studio, on the top right there is an “eye” icon, click it and it should go away.

In game not in studio……………………

I see, alright, well you can listen to the other guy, @8Jonesloto8

Using a separate function won’t do anything though.

You can access player’s backpack by next code:

game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("ToolName")

Just make sure you use it as if statement when script knows if Humanoid exists.

Do you mind incorporating it into my script above?

Maybe you can do a wait() and make the transparency of the frame 1 after the assets is loaded. You can change the background transparency.

You will have to change ToolName as your tool name, name. Here is how it should look like:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = false
local Values = script.Parent.Values
local BusinessClassName = Values.BusinessClassName.Value
local BusinessClassTicket = Values.BusinessClassTicket
local BusinessRank = Values.BusinessRank.Value
local Class3 = Values.Class3.Value
local EconomyClassName = Values.EconomyClassName.Value
local EconomyClassTicket = Values.EconomyClassTicket
local EconomyRank = Values.EconomyRank.Value
local FirstClassName = Values.FirstClassName.Value
local FirstClassTicket = Values.FirstClassTicket
local FirstClassRank = Values.FirstClassRank.Value
local InvestorClassName = Values.InvestorClassName.Value
local InvestorClassTicket = Values.InvestorClassTicket
local InvestorRank = Values.InvestorRank.Value
local groupID = Values.groupID.Value
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = game.ReplicatedStorage



local Brick = script.Parent.SCIParts.Touch

Brick.Touched:Connect(function(hit)
	if debounce then
		return
	end

	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("ToolName") then      --Change here your tool name
			debounce = true
			local Gui = game.ReplicatedStorage:WaitForChild("LoadingGUI")
			local GuiClone = Gui:Clone()
			GuiClone.Parent = Player:WaitForChild("PlayerGui")
			local rank = Player:GetRankInGroup(groupID)
			Player:WaitForChild("Backpack")
			local ticket = nil
			if rank == EconomyRank then
				ticket = ReplicatedStorage:WaitForChild(EconomyClassTicket.Value)
			elseif rank == BusinessRank  then
				ticket = ReplicatedStorage:WaitForChild(BusinessClassTicket.Value)
			elseif Class3 == false then
				if rank == FirstClassRank then
					ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
				elseif rank >= InvestorRank then
					ticket = ReplicatedStorage:WaitForChild(InvestorClassTicket.Value)	
				end
			elseif rank >= FirstClassRank then
				ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
			end 
			if ticket then
				local alreadyHasTicket = Player.Backpack:FindFirstChild( ticket.Name ) or Player.Character:FindFirstChild( ticket.Name )
				if not alreadyHasTicket then
					ticket:Clone().Parent = Player.Backpack
				end 
			end 
			wait(5)
			debounce = false
		end 
	end 
end)

How do I make it so it makes sure that you do not have one of four tools?

Hello. Are you still there???

You can just copy and paste statement condition four times and it should be good but make sure to change location of a tool.

Do I need to put an “or” in between each one?

Just add “and” in between.

30 characters.

It does not seem to work. I have an idea though. There is a part in my script where it says:

Brick.Touched:Connect(function(hit)
	if debounce then
		return
	end

What if I make the script look through the backpack there and if there is anything it returns?

Can you show me your script how you edited it? You will have to touch a brick then, do you think that would be sufficient enough?


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Values = script.Parent.Values
local BusinessClassName = Values.BusinessClassName.Value
local BusinessClassTicket = Values.BusinessClassTicket
local BusinessRank = Values.BusinessRank.Value
local Class3 = Values.Class3.Value
local EconomyClassName = Values.EconomyClassName.Value
local EconomyClassTicket = Values.EconomyClassTicket
local EconomyRank = Values.EconomyRank.Value
local FirstClassName = Values.FirstClassName.Value
local FirstClassTicket = Values.FirstClassTicket
local FirstClassRank = Values.FirstClassRank.Value
local InvestorClassName = Values.InvestorClassName.Value
local InvestorClassTicket = Values.InvestorClassTicket
local InvestorRank = Values.InvestorRank.Value
local groupID = Values.groupID.Value
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = game.ReplicatedStorage



local Brick = script.Parent.SCIParts.Touch

Brick.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Economy Class Ticket") and game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Business Class Ticket") and game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("First Class Ticket") and game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Investor Class Ticket ")
			local Gui = game.ReplicatedStorage:WaitForChild("LoadingGUI")
			local GuiClone = Gui:Clone()
			GuiClone.Parent = Player:WaitForChild("PlayerGui")
			local rank = Player:GetRankInGroup(groupID)
			Player:WaitForChild("Backpack")
			local ticket = nil
			if rank == EconomyRank then
				ticket = ReplicatedStorage:WaitForChild(EconomyClassTicket.Value)
			elseif rank == BusinessRank  then
				ticket = ReplicatedStorage:WaitForChild(BusinessClassTicket.Value)
			elseif Class3 == false then
				if rank == FirstClassRank then
					ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
				elseif rank >= InvestorRank then
					ticket = ReplicatedStorage:WaitForChild(InvestorClassTicket.Value)	
				end
			elseif rank >= FirstClassRank then
				ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
			end 
			if ticket then
				local alreadyHasTicket = Player.Backpack:FindFirstChild( ticket.Name ) or Player.Character:FindFirstChild( ticket.Name )
				if not alreadyHasTicket then
					ticket:Clone().Parent = Player.Backpack
				end 
			end 

		end 

	end 

You forgot to add “not” next to “and”. Make sure that there is no any whitespaces if your tool doesn’t have it either inside of a string you are checking.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Values = script.Parent.Values
local BusinessClassName = Values.BusinessClassName.Value
local BusinessClassTicket = Values.BusinessClassTicket
local BusinessRank = Values.BusinessRank.Value
local Class3 = Values.Class3.Value
local EconomyClassName = Values.EconomyClassName.Value
local EconomyClassTicket = Values.EconomyClassTicket
local EconomyRank = Values.EconomyRank.Value
local FirstClassName = Values.FirstClassName.Value
local FirstClassTicket = Values.FirstClassTicket
local FirstClassRank = Values.FirstClassRank.Value
local InvestorClassName = Values.InvestorClassName.Value
local InvestorClassTicket = Values.InvestorClassTicket
local InvestorRank = Values.InvestorRank.Value
local groupID = Values.groupID.Value
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = game.ReplicatedStorage



local Brick = script.Parent.SCIParts.Touch

Brick.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Economy Class Ticket") and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Business Class Ticket") and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("First Class Ticket") and not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Backpack:FindFirstChild("Investor Class Ticket") then
			local Gui = game.ReplicatedStorage:WaitForChild("LoadingGUI")
			local GuiClone = Gui:Clone()
			GuiClone.Parent = Player:WaitForChild("PlayerGui")
			local rank = Player:GetRankInGroup(groupID)
			Player:WaitForChild("Backpack")
			local ticket = nil
			if rank == EconomyRank then
				ticket = ReplicatedStorage:WaitForChild(EconomyClassTicket.Value)
			elseif rank == BusinessRank  then
				ticket = ReplicatedStorage:WaitForChild(BusinessClassTicket.Value)
			elseif Class3 == false then
				if rank == FirstClassRank then
					ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
				elseif rank >= InvestorRank then
					ticket = ReplicatedStorage:WaitForChild(InvestorClassTicket.Value)	
				end
			elseif rank >= FirstClassRank then
				ticket = ReplicatedStorage:WaitForChild(FirstClassTicket.Value)
			end 
			if ticket then
				local alreadyHasTicket = Player.Backpack:FindFirstChild( ticket.Name ) or Player.Character:FindFirstChild( ticket.Name )
				if not alreadyHasTicket then
					ticket:Clone().Parent = Player.Backpack
				end 
			end 
		end 
	end

Im confused. What do you mean by “Make sure that there is no any whitespaces if your tool doesn’t have it either inside of a string you are checking.”