UserInputService does nothing

I want to make it so the camera offsets a little bit corresponding to the key that is pressed (if you press A your camera offset to the left). Using my limited knowledge of the Lua language, I have re-coded this twice, and I just want this movement system to be over with.
(This is only the A)

Userinputservice.InputBegan:Connect(function(Input)

	if Input.KeyCode == Enum.KeyCode.A then 
		if Info > Vector3.new(-0.2,0,0) then
			while Info > Vector3.new(-0.2,0,0) do
				wait(0.05)
				Info = Info - Vector3.new(0.05,0,0)
			end
		end
	end
end)

Userinputservice.InputEnded:Connect(function(Input)
	
	if Input.KeyCode == Enum.KeyCode.A then
		if Info < Vector3.new(0,0,0) then 
			while Info < Vector3.new(0,0,0) do
				wait(0.05)
				Info = Info + Vector3.new(0.05,0,0) 
			end
		end
	end
end)

The problem is it’s choosing to ignore it, and if it’s not then it is not changing the value.
Can you please tell my why this is happening, my mistakes, and what to do next time. :slight_smile:

What is Info equal to? Is there more of the script that is not included in the post?

Yeah but its 200 lines of code. I’m using the roblox bobble effect or

local RunService = game:GetService("RunService")
 
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
 
local function updateBobbleEffect()
	local now = tick()
	if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
		local velocity = humanoid.RootPart.Velocity
		local bobble_X = math.cos(now * 9) / 5
		local bobble_Y = math.abs(math.sin(now * 12)) / 5
		
		local bobble = Vector3.new(bobble_X,bobble_Y,0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)
	else
		-- Scale down the CameraOffset so that it shifts back to its regular position.
		humanoid.CameraOffset = humanoid.CameraOffset * 0.75
	end
end
 
-- Update the effect on every single frame.
RunService.RenderStepped:Connect(updateBobbleEffect)

so what I wanted to do Is use the same system but add with info
so info is a vector3.new(0,0,0)

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)+ Info

Where in your script does the camera offset get set to the Info variable? If you change the variable without changing the camera offset, it will seemingly do nothing.

1 Like

The problem is the value isn’t changing as well
info is remained as the same

In order to debug this, add random print statements in the InputBegan and InputEnded listeners, see if they’re even firing at all.

Preferably under this line.

1 Like

I did, I put a print to see if it’s firing at all, and then it printed
but the value was the same

Therefore, the above if statement is false. The same applies to the other one. It is not changing because it does not meet the requirements of the if statement.

I take that back
but it doesn’t work when you start it

I noticed it no-longer works with print.
Can you help me fix this because it’s not detecting that A is being pressed.

If you’re trying to detect if a key is being held you can do,

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input)
 if Input.KeyCode == Enum.KeyCode.A then
  while wait() do
   local DetectKeyInput = UserInputService:IsKeyDown(Enum.KeyCode.A)

   if not DetectKeyInput then
     break
   end
   print("KeyInput is still being held.")
  end
 end
end)

(This is for reference), not the greatest but it’s an understandable solution to detecting if a keyinput is being held.)

local userInput = game:GetService("UserInputService")

local inputConn
inputConn = userInput.InputBegan:Connect(function(key, processed)
	if processed then return end
	if key.KeyCode == Enum.KeyCode.F then
		print("F key held.")
		local keyStart = tick()
		local outputConn
		outputConn = userInput.InputEnded:Connect(function(key, processed)
			if processed then return end

			if key.KeyCode == Enum.KeyCode.F then
				print("F key released.")
				local keyEnd = tick()
				print("Key held for "..keyEnd - keyStart.." seconds.")
				inputConn:Disconnect()
				outputConn:Disconnect()
			end
		end)
	end
end)

This is personally how I go about achieving key held/key released detecting.

image

1 Like

Is processed as if it like clicked? I am looking at the Roblox documentation and it doesn’t define it well.
and why are you making an input/output connection as a variable and what is disconnect mean?