I have a plane system that uses KeyCodes to determine when a player flying the plane wants to speed up, slow down, turn on/off the engine, etc.
An issue I have encountered is, if I am typing in chat, and there is a word/phrase/sentence that uses the same letters used to control the planes, those keys will fire, even though I am only typing and do not wish to do that action.
How do I prevent KeyCode actions from being fired/acted on when a player is chatting?
Here is my code:
USINS.InputBegan:connect(function(input)
local code=input.KeyCode
if code==Enum.KeyCode.S or code==Enum.KeyCode.DPadDown then
remote:InvokeServer("-") --- slow down
elseif code==Enum.KeyCode.W or code==Enum.KeyCode.DPadUp then
remote:InvokeServer("+") --- speed up
elseif code==Enum.KeyCode.Y or input.KeyCode == Enum.KeyCode.ButtonY then
remote:InvokeServer("engine") --- toggle engine
end
end)
USINS.InputBegan:connect(function(input, gameProcessed)
if (gameProcessed) then
return
end
local code=input.KeyCode
if code==Enum.KeyCode.S or code==Enum.KeyCode.DPadDown then
remote:InvokeServer("-") --- slow down
elseif code==Enum.KeyCode.W or code==Enum.KeyCode.DPadUp then
remote:InvokeServer("+") --- speed up
elseif code==Enum.KeyCode.Y or input.KeyCode == Enum.KeyCode.ButtonY then
remote:InvokeServer("engine") --- toggle engine
end
end)
It’s just in the style I write in. It doesn’t do anything, just makes it easier for me to read. And also because of how I write in different languages such as C#.