How to control Xbox selection GUI?

I am attempting to make an inventory system that theoretically works on Xbox. Basically, what I want to happen, is that the player presses the selection button and their inventory opens, like a normal console game, but Roblox decided that it would be a good idea to use that button. So I’m wondering if I could disable that so I could use it because in my game, the player should never have to press it to select ui, which brings me to my next question.

When the player does open their inventory, I want to force the player to select a ui element so they can do their thing and I do not want them to be able to unselect the ui while their inventory is still open, when the player exits out of their inventory, then I want it to unselect for them, like I said, the player should never have to press the select button (I see why Roblox uses the select button, but this method of selecting ui is disgusting). Right now my code looks like this:

GUI_SERVICE:AddSelectionParent("Inventory", INV_FRAME)
GUI_SERVICE.SelectedObject = INV_SCROLLING_FRAME:FindFirstChild("tempItemFrame")
INV_FRAME.Visible = true

It opens their inventory (currently, I am using the ‘Y’ button until I can figure out how to use the select button) and it selects a button in their inventory, but the player can just press the select button and unselect the menu, which I don’t want. Solutions?

2 Likes

hey, did you ever find a solution? I am looking to do the same thing in my game. It’s crazy that there is no documentation on this topic.

Yes, actually I did!

First off: You’re welcome, I spent like 3 weeks trying to find literally anything that would help me find a solution, but I finally found it. It’s funny, you would think that there would be more resources, since there is a large community of Roblox Xbox players.

-- Services --

local PLAYERS = game:GetService('Players')
local INPUT_SERVICE = game:GetService('UserInputService')
local GUI_SERVICE = game:GetService('GuiService')

-- Player-Vars --

local PLAYER = PLAYERS.LocalPlayer
local PLAYER_GUI = PLAYERS:WaitForChild("PlayerGui")
local LAST_SELECTION

-- Functions --

 -- So that you can set the selection for GUI from anywhere. Just pass a selectable GUI object
local function SetSelection(newSelection)
	if (newSelection and newSelection ~= GUI_SERVICE.SelectedObject) then
		LAST_SELECTION = newSelection
		GUI_SERVICE.SelectedObject = newSelection
	end
end

-- Code --



 -- Disable all Roblox's default Xbox crap. This makes it so that the player can't select and deselect with the select button
GUI_SERVICE.AutoSelectGuiEnabled = false
GUI_SERVICE.GuiNavigationEnabled = true

 -- You can set this to an image-object to change the selection for all GUI objects
PLAYER_GUI.SelectionImageObject = ""

-- Events --

 -- Make sure we always know what is selected in case the GUI gets unselected early
GUI_SERVICE:GetPropertyChangedSignal("SelectedObject"):Connect(function()
	if (GUI_SERVICE.SelectedObject and GUI_SERVICE.SelectedObject ~= LAST_SELECTION) then
		LAST_SELECTION = GUI_SERVICE.SelectedObject
	end
end)

 -- When the menu is opened, all other selected gui elements will be unselected, so we need to make sure to reselect the last selected GUI element after the menu is closed
GUI_SERVICE:GetPropertyChangedSignal("MenuIsOpen"):Connect(function()
	-- A check to make sure that the player is on Xbox. You'll have to write your own code to do this, I already have mine
	if (PLAYER.device == "xbox") then
		if (not GUI_SERVICE.MenuIsOpen) and (LAST_SELECTION) then
			GUI_SERVICE.SelectedObject = LAST_SELECTION
		end
	end
end)

This will allow you to have complete control over what the player selects, can select, and can’t select.

To deselect an element, you can simply type:

GUI_SERVICE.SelectedObject = nil

LAST_SELECTION = nil -- Optional

I hope this helps you as it helped me. Let me know if you have any questions.

Resources:

GuiService
SelectedObject
GuiNavigationEnabled
CoreGuiNavigationEnabled
MenuIsOpen

11 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.