Working SelectedObject?

I kinda have 2 questions relating to coding UI for console.

First: I’m using SelectionImageObject with a frame I have, to replace the neon blue one that is default for SelectedObject It works to an extent. When I test the Selected frame I’m using is to the right of the text, and at the top of the screen, but when I use the control to go up and down it moves up and down, but in the centre of the screen. The Selected frame is the yellow frame next to the Text. How I move the Selected frame with the mouse (:TweenPosition()) is where I want the Selected frame to be.

Which then leads to my second question: I’m using MouseEnter and MouseLeave to do animations to the text (Change the font and move the Selected frame to next to the text) Was wondering if there is a way to do this with console, without detecting if selected = “DeployButton”, selected = “GunsButton”, etc.

Here’s what I have

local guiService = game:GetService('GuiService')
local players = game:GetService('Players')
local userInputService = game:GetService('UserInputService')
local contextActionService = game:GetService('ContextActionService')

local player = players.LocalPlayer
local playerGui = player:WaitForChild('PlayerGui')

local mouse = player:GetMouse()

local frame = script.Parent

local selected = frame:WaitForChild('Selected')

local deployButton = frame:WaitForChild('DeployButton')
local gunButton = frame:WaitForChild('GunButton')
local boostButton = frame:WaitForChild('BoostButton')
local statButton = frame:WaitForChild('StatButton')

playerGui.SelectionImageObject = selected

if userInputService.GamepadEnabled then
	guiService:AddSelectionParent('Menu', frame)
	guiService.SelectedObject = deployButton
end

deployButton.MouseButton1Down:connect(function()
	frame:Destroy()
end)

for _, button in pairs(frame:GetChildren()) do
	if button.ClassName == 'TextButton' then
		button.MouseEnter:connect(function()
			button.Font = 'SourceSansBold'
			selected:TweenPosition(UDim2.new(button.Position.X.Scale - 0.25, 0, button.Position.Y.Scale, 0), 'Out', 'Quint', 0.25, true)
		end)
		button.MouseLeave:connect(function()
			button.Font = 'SourceSansSemibold'
		end)
	end
end

It appears you have already solved the latter problem somewhat; you already have the correct calculations and just need to detect when the selection is changed and what it selected.

You can do this manually, like you said, or the other option I see is listening to the Selection gained signal for each button:
(This goes in the button for loop you had)

Button.SelectionGained:Connect(function()
    -- tween
end)

For that first question, can you show us an example of that wrong behavior? A little confused on what exactly is wrong there

I don’t know how to add videos in here, but here’s pictures of what’s happening.


As you can see, when I move the joystick down, the yellow bar seems to go down as well, but it’s for some reason to the left and up from the buttons. If you look carefully you can see each button is indented and in a bolder font, but yeah, the yellow thing isn’t where it should be. It’s also a lot wider than how I scaled it in studio. When i test without the controller it’s in the right spot and the right size but yeah :confused:

Just removedthe SelectedObjectImage so its back to Roblox’s default one, and it works perfectly, but I really don’t want the neon blue :confused:

1 Like