I tried using the line if script.Parent.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.FocusLost then
but that didn't even work. What I'm trying to do is make it so that when keys are pressed and the chat or another gui is in focus, it won't run the function.
Here is the full script, for anyone who is interested.
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local hmnid = char:WaitForChild("Humanoid") function onKeyPress(inputObject, gameProcessedEvent) if script.Parent.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.FocusLost then if inputObject.KeyCode == Enum.KeyCode.K then if hmnid.CameraOffset.x ~= 5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X + 0.5, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z) print("CameraOffset X value increased.") else print("CameraOffset not changed.") end end if inputObject.KeyCode == Enum.KeyCode.H then if hmnid.CameraOffset.x ~= -5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X - 0.5, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z) print("CameraOffset X value decreased.") else print("CameraOffset not changed.") end end if inputObject.KeyCode == Enum.KeyCode.J then if hmnid.CameraOffset.z ~= 5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z + 0.5) print("CameraOffset Z value increased.") else print("CameraOffset not changed.") end end if inputObject.KeyCode == Enum.KeyCode.U then if hmnid.CameraOffset.z ~= -5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z - 0.5) print("CameraOffset Z value decreased.") else print("CameraOffset not changed.") end end if inputObject.KeyCode == Enum.KeyCode.Y then if hmnid.CameraOffset.y ~= 5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y + 0.5, hmnid.CameraOffset.Z) print("CameraOffset Y value increased.") else print("CameraOffset not changed.") end end if inputObject.KeyCode == Enum.KeyCode.N then if hmnid.CameraOffset.y ~= -5 then hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y - 0.5, hmnid.CameraOffset.Z) print("CameraOffset Y value decreased.") else print("CameraOffset not changed.") end end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
You could check if game:GetService("UserInputService"):GetFocusedTextBox()
is nil, because that means there is no textbox is focused, so it won't run if you are focused on a text box