When ever I use UIS and press say the letter "F", the script I have changes a fire mode on a gun. It works just fine. The problem comes from when I try to type something in chat, for example:
"Hold your fire, those are friendlies."
There are 2 "F"s in that message, so it changes the fire mode twice during a message like that when you're not actually doing anything. On many guns, this might cycle it to SAFETY from Full Auto, which for obvious reasons is a big problem in say a PVP environment, especially if the player isn't paying attention to the fire modes. I've gone looking in the Roblox Discord, I've looked on the Roblox Wiki as well. The Wiki doesn't seem to provide many examples for what the people on the Roblox Discord are telling me to do and they seem to have trouble providing an example for me as well. Can someone help clear this up?
you can set a value to true whenever they're in a textbox with the Events TextBoxFocused
and TextBoxFocusReleased
, then use an extra if-then to determine if the value is true or not. Here's an example:
local userinputservice = game:GetService("UserInputService") --- The main part --- local inChat = false userinputservice.TextBoxFocused:connect(function() inChat = true end userinputservice.TextBoxFocusReleased:connect(function() inChat = false end ------ --Example with InputBegan userinputservice.InputBegan:connect(function(inputObject) if inputObject.KeyCode == Enum.KeyCode.X then if inChat = false then print("Working!") end end end)
Note: I haven't tested this script yet because this computer can't run roblox, but feel free to test it and let me know if there are any errors.
UserInputService's events InputBegan
, InputEnded
, and InputChanged
all have two parameters: KeyCode and gameProcessed. gameProcessed basically means, like you said, when a player is chatting, the event will not fire, or rather won't run the code.
In a local script:
local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(key,gameProc) if not gameProc then if key.KeyCode == Enum.KeyCode.E then print(1) end end end)