PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Creating a Grid Menu Code Sample 1

Creating a Grid Menu Code Sample 1

Oct 01 2018, 3:02 AM PST

-- Closes the equipment menu
local function closeEquipmentMenu()
	-- Play closing animation
	menuFrame:TweenPosition(MENU_CLOSED_POSITION, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, false, function(status)
		-- When animation finished, unbind the close function and reset Gui selection		
		ContextActionService:UnbindAction(CLOSE_EQUIPMENT_MENU_BINDING)
		GuiService.SelectedObject = nil
		GuiService.AutoSelectGuiEnabled = oldAutoSelectGuiEnabled
	end)
end

-- Opens the equipment menu
local function openEquipmentMenu()
	-- Store the old value of AutoSelectEnabled and then set to false
	oldAutoSelectGuiEnabled = GuiService.AutoSelectGuiEnabled
	GuiService.AutoSelectGuiEnabled = false
	
	-- Play opening animation
	menuFrame:TweenPosition(MENU_OPEN_POSITION, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, false, function(status)
		-- When animation finished, bind closeEquipmentMenu to the B button
		ContextActionService:BindAction(CLOSE_EQUIPMENT_MENU_BINDING, function(actionName, inputState, inputObject)
			if inputState == Enum.UserInputState.Begin then
				closeEquipmentMenu()
			end
		end, false, Enum.KeyCode.ButtonB)
		-- Select torso by default
		GuiService.SelectedObject = torsoFrame
	end)
end

-- Input binding
equipmentButton.MouseButton1Click:Connect(openEquipmentMenu)