Inventory will not hide when I activate Tool

  1. What do you want to achieve? Keep it simple and clear!

I want my inventory to hide when I activate a tool and then re-appear after I activate the tool again.

  1. What is the issue? Include screenshots / videos if possible!

When I activate the Tool the inventory won’t hide. There was no error in the output either.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked for solutions on many posts but none seem to be the solution to my problem.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is the script that I ended up with:

local Debounce = false

script.Parent.Activated:Connect(function()
	
	if Debounce == false then
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
	
	Debounce = true
		
	end
	
	
	if Debounce == true then
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	

	Debounce = false
	end
	
	
end)

I would be happy if anyone could help me!

Can you add print() functions to see if the script enters the if statements? It looks fine to me. Tell me which strings print and which don’t.

1 Like

It is because when you activate the tool, it passes the first if statement AND passes the 2nd, so it is hiding, but is also unhiding immediately after. This case you’d need an if-else statement, not 2 if statements. Though I’d make it even simpler through the not operator (which just inverts) and using GetCoreGuiEnabled

local StarterGui = game:GetService("StarterGui")

local coreGui = Enum.CoreGuiType.Backpack

script.Parent.Activated:Connect(function()
	StarterGui:SetCoreGuiEnabled(coreGui, not StarterGui:GetCoreGuiEnabled(coreGui))
end)
1 Like

It’s possible that you’re using a regular script to do this, along with the above mentioned reasons.

If you’re using a regular script, change it to a localscript.

1 Like