Why does alt trigger in Studio, but not in Roblox?

I have a script that detects, when player presses LeftAlt, but it only works in Studio.

local UIS = game:GetService("UserInputService")
local Body = workspace["DAF XF"].Body
local Camera = workspace.Camera

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftAlt then
		if Camera.FieldOfView == 25 then
			Camera.FieldOfView = 70
		else
			Camera.FieldOfView = 25
			
		end
	end
end)

try to set workspace.CurrentCamera instead workspace.Camera

1 Like

That does still nothing after I pressed LeftAlt

1 Like

try to paste this script and show me what it outputs

local UIS = game:GetService("UserInputService")
local Body = workspace["DAF XF"].Body
local Camera = workspace.Camera

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftAlt then
		print("Input Began 1")
		if Camera.FieldOfView == 25 then
			Camera.FieldOfView = 70
		else
			Camera.FieldOfView = 25
		end
	end
end)

I checked and the script is working correctly, it looks like the problem is in another part of the script.


1 Like

Try creating a new local script in StarterGui with this code and see if it works.

local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftAlt then
		if Camera.FieldOfView == 25 then
			Camera.FieldOfView = 70
		else
			Camera.FieldOfView = 25
		end
	end
end)

Well it is thew same code and from my expierience, no. It only appears, that it only works in Studio.

Yes, this is the same code, but with the help of a new script you can understand what exactly the problem is.

Perhaps your script contains something that does not work correctly, or there is another script that changes the value of FieldOfView.