I was looking to change the text of a button to say which key should be pressed to open a UI, depending on the input type. It works fine with keyboard and gamepad buttons, but nothing happens when I tilt the control sticks and there is nothing in output. Why?
Here’s my script: (a local script inside a button in ScreenGUI)
local inputServ = game:GetService("UserInputService")
local gamepadServ = game:GetService("GamepadService")
local defaultString = script.Parent.Text
function showHints()
script.Parent.Parent.HintContainer.Hints.Visible = not script.Parent.Parent.HintContainer.Hints.Visible
script.Parent.Parent.ModalButton.Visible = not script.Parent.Parent.ModalButton.Visible
script.Parent.Parent.ModalButton.Active = not script.Parent.Parent.ModalButton.Active
if script.Parent.Parent.HintContainer.Hints.Visible then
gamepadServ:EnableGamepadCursor(script.Parent.Parent.HintContainer.Hints)
else
gamepadServ:DisableGamepadCursor()
end
end
script.Parent.Activated:Connect(showHints)
inputServ.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch then
script.Parent.Text = defaultString
end
if input.UserInputType == Enum.UserInputType.Keyboard
or input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.MouseButton2
or input.UserInputType == Enum.UserInputType.MouseButton3
or input.UserInputType == Enum.UserInputType.MouseWheel
or input.UserInputType == Enum.UserInputType.MouseMovement
then
script.Parent.Text = defaultString.."(H)"
if input.KeyCode == Enum.KeyCode.H then
showHints()
end
end
if input.UserInputType == Enum.UserInputType.Gamepad1 then
script.Parent.Text = defaultString.."(Y/Triangle)"
if input.KeyCode == Enum.KeyCode.ButtonY then
showHints()
end
end
end)