-- Decides when the GUI should be hidden.
-- 
-- ForbiddenJ


UserInputService = game:GetService("UserInputService")

IsDisplayed = script.Parent.IsDisplayed
IsHiddenByOtherGUI = script.Parent.IsHiddenByOtherGUI
HideGuiEnabled = game.ReplicatedStorage.ClientConfig.HideGuiEnabled
IsGameMenuOpen = script.Parent.Parent.GameMenu.IsOpen

MouseHovering = false

function Update()
	IsDisplayed.Value =
		(not HideGuiEnabled.Value or MouseHovering or UserInputService.TouchEnabled) and not IsHiddenByOtherGUI.Value
end

HideGuiEnabled.Changed:Connect(Update)
IsHiddenByOtherGUI.Changed:Connect(Update)
IsGameMenuOpen.Changed:Connect(function(value)
	IsHiddenByOtherGUI.Value = value
end)
UserInputService:GetPropertyChangedSignal("MouseEnabled"):Connect(Update)
script.Parent.MouseEnter:Connect(function()
	MouseHovering = true
	Update()
end)
script.Parent.MouseLeave:Connect(function()
	MouseHovering = false
	Update()
end)

IsHiddenByOtherGUI.Value = IsGameMenuOpen.Value
Update()
