I’m making a control scheme which heavily relies on controls starting and ending. In specific, I’m using ContextActionService for this. Here’s a bit of code:
local function onLeft(actionName, inputState : Enum.UserInputState, inputObject : InputObject)
if inputObject.KeyCode == Enum.KeyCode.Unknown then return end
if char == nil then return end
if inputState == Enum.UserInputState.Begin then
horizontal -= 1
if horizontal < -1 then
horizontal = -1
end
elseif inputState == Enum.UserInputState.End then
horizontal += 1
end
end
This works fine, however has the downside of the “End” not being registered if the user were to hold the left button, then press / to enter chat. I added a quick hotfix (if horizontal < -1) to fix issues like being able to get horizontal as a value outside of -1 to 1, and it helps reset it to 0, but then I was wondering if there’s a way to detect when the user enters chat and then terminate it prematurely. I can’t just detect if the user presses slash, for example, because the same thing happens when you click directly on the chat box.
If anyone knows any ways to help fix this, that would be much appreciated.
When the player opens chat (either by pressing / or clicking the box), Roblox basically stops sending the End state, so your code never knows they let go.
Easiest fix: listen for when the chat box gets focused and just reset your values yourself.
local UserInputService = game:GetService("UserInputService")
UserInputService.TextBoxFocused:Connect(function()
-- Player entered chat, reset movement
horizontal = 0
end)
UserInputService.TextBoxFocusReleased:Connect(function()
-- Back out of chat, inputs will fire again
end)
You can also just check if the player is typing before handling input:
if UserInputService:GetFocusedTextBox() then
return
end
So instead of waiting for End (which you won’t get when chat opens), just reset horizontal when focus shifts to chat. Keeps everything clean.
Its intended replacement, Input Action System (IAS) is still very much in it’s infancy – it’s a client beta. It’s got its issues, such as bugs, and some may prefer UIS/CAS over it because of workflows or because it’s ‘Instance-Based’.
It also doesn’t completely cover all use-cases, such as the LocalToolEquipped/Unequipped events.