UserInputService.KeyboardEnabled is broken?!

I’m writing code so that if the keyboard is enabled, then it sets the camera to a part in the workspace’s Cframe. Setting the camera works, its the UserInput that doesn’t. According to Roblox, the TouchEnabled goes in an if loop. This is my code, it is located inside a LocalScript within StarterGui.

local userInputService = game:GetService("UserInputService")

if (userInputService.KeyboardEnabled) then
	local function updateCameraCFRAME()
		game.Workspace.CurrentCamera.CFrame = game.Workspace.CameraPart.CFrame
	end
	game:GetService("RunService").RenderStepped:Connect(updateCameraCFRAME)
end

Resources: UserInputService | Roblox Creator Documentation

put the RenderStepped:Connect() outside of the if statement, preferably at the end of the script

never mind, i read the code wrong

I had a similar issue a while back and found a post on this forum (can’t find it again sorry) that helped. It seems that Roblox can’t tell what the input device is until the user has actually used the input device, which is why the loop is needed for TouchEnabled. It may be completely different issue, but thought I should mention it.

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local camera = workspace.CurrentCamera
local cameraPart = workspace.CameraPart

local function updateCameraCFRAME()
	camera.CFrame = cameraPart.CFrame
end

UIS.InputBegan:Wait()
if UIS.KeyboardEnabled then
	RS.RenderStepped:Connect(updateCameraCFRAME)
end

Just wait for the InputBegan event to fire before the conditional check is performed.

You need to set the camera to scriptable.

You can script the camera without doing that.