I have no idea what to do right now. My mind is just cluttered. I will try again later, but thank you for explaining.
Wait, so really all I have to do is just use UserInputService/ContextActionService, bind that to Enum.KeyCode.Up or Enum.KeyCode.Down, then set the first button as a parameter in GuiService:Select().
And make a variable that increases by 1 every time the bind runs. Depends on what direction the player is going. Whether it’s up, down, left, or right.
When the player reaches the last button, reset the variable.
I guess that’s it O_O
Yeah, something like this:
local guiService = game:GetService("GuiService")
local uis = game:GetService("UserInputService")
local items = {} --add your selectable items
local currentSelected = 0
local function onInputBegan(input: InputObject, processed: boolean)
if processed then return nil end
local toAdd = if input.KeyCode == Enum.KeyCode.Down then -1
elseif input.KeyCode == Enum.KeyCode.Up then 1 else nil
if not toAdd then return nil end
currentSelected += math.clamp(toAdd, 1, #items)
guiService:Select(items[currentSelected])
end
uis.InputBegan:Connect(onInputBegan)
So, can I make the button have a highlight effect like this? Or is there a better way to do it?
SaveSlotsList[selectedKeys].BackgroundColor3 = Color3.fromRGB(255, 255, 0)
task.wait(0.25)
SaveSlotsList[selectedKeys].BackgroundColor3 = Color3.fromRGB(25, 25, 25)
So it was really as simple as having a variable that increases or decreases when the player does a certain input, then plugging that into a table and using GuiService:Select(). And adding some highlight effects.
Man, I was overthinking. By the way I put SelectionOrder manually on every button so it works.
I’m assuming there’s more than one way to do it, with the effects as well.
Yeah, you could show the highlight like that. There’s some other ways, like placing a UIStroke
with Border
mode to show it. All depends on what you think would look better.
Yeah, but the button has a UICorner. So I just tweened the color.
Sounds good!
Let me know if you have any more questions or issues. Otherwise, make sure to mark this topic as solved so it can close.
If you want a simpler way to have all your buttons selectable, tag them and then use CollectionService:GetTagged()
.
I’m just going to make console support now. I disabled the default GuiService.AutoSelectGuiEnabled.
By the way, for console, I just used Enum.KeyCode.DPadUp and DPadDown.
This is kind of personal, but. What should I name my game? It’s an RPG/party game.
Im not too sure, depends on what your game is, concept, etc. If you need help naming it, I reckon you could get some help in #help-and-feedback:game-design-support .
Thank you for your help! I appreciate it.
Alright, I have another issue. So, when the player hovers on a button, the button color tweens. Right. That’s good.
But when the player uses arrow key navigation and tries to have their mouse hovering, it causes the color to go away, even though the player’s mouse is still hovering over it.
Mouse part:
local ChangeButtonProperties = TweenService:Create(
child,
TweenInfo.new(0.25),
{Size = UDim2.new(1, 0, 0.175, 0), BackgroundColor3 = Color3.fromRGB(0, 206, 255)}
)
local RevertButtonProperties = TweenService:Create(
child,
TweenInfo.new(0.25),
{Size = UDim2.new(0.8, 0, 0.15, 0), BackgroundColor3 = Color3.fromRGB(25, 25, 25)}
)
child.MouseEnter:Connect(function()
HoverSound:Play()
ChangeButtonProperties:Play()
ChangeButtonProperties.Completed:Wait()
end)
child.MouseLeave:Connect(function()
RevertButtonProperties:Play()
ChangeButtonProperties.Completed:Wait()
end)
Arrow/DPad part
local StartHighlight = TweenService:Create(
SaveSlotsList[selectedKey],
TweenInfo.new(0.25),
{BackgroundColor3 = Color3.fromRGB(0, 206, 255)}
)
local EndHighlight = TweenService:Create(
SaveSlotsList[selectedKey],
TweenInfo.new(0.25),
{BackgroundColor3 = Color3.fromRGB(25, 25, 25)}
)
StartHighlight:Play()
StartHighlight.Completed:Wait()
EndHighlight:Play()
EndHighlight.Completed:Wait()
Just put in a quick check for when they leave that selection to make sure the mouse button isn’t hovering over it.
local uis = game:GetService("UserInputService")
local plrGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local targetButton = --button you want to check against
--then...
local location = uis:GetMouseLocation()
local objects = plrGui:GetGuiObjectsAtPosition(location.X, location.Y)
if table.find(objects, targetButton) then
print("Player's mouse is hovering over the button.")
end
I had no idea those functions existed. Could you link me more info about them?
Sure!
BasePlayerGui:GetGuiObjectsAtPosition() | Documentation - Roblox Creator Hub
UserInputService:GetMouseLocation() | Documentation - Roblox Creator Hub
Um, it’s printing nil out. When I print:
Make sure your mouse is over the button. You’ll also need to make sure it’s updated with the current mouse position after moving it.
Like this?
while true do
task.wait(1)
local MouseLocation = UserInputService:GetMouseLocation()
end
or
local MouseLocation = nil
while true do
task.wait(1)
MouseLocation = UserInputService:GetMouseLocation()
end
The second one would work better, but since this is for your navigation script, you can just check it when they attempt to select a new object.