In my game I have it so players are locked in first person. However, I have some on-screen elements that they need to interact with, so occasionally I’d like them to have their mouse free. I want the player to be able to free their mouse whenever they press [F3].
The issue is that this will not work with the F3 key. Here is how I have the applicable part of the script written. This is written in a LocalScript placed inside StarterPlayerScripts.
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F3 then
ToggleFreeMouse();
end
end)
I tried searching but was unable to find anyone having trouble using the function keys. I also tried binding it to another key, such as [F], and it worked just fine. Is it even possible to utilize the function row for keybinds inside Roblox?
Here is the entire script, if it matters.
local Players = game:GetService("Players");
local UserInputService = game:GetService("UserInputService");
local player = Players.LocalPlayer;
local PlayerHud = player.PlayerGui:WaitForChild("PlayerHud")
local Crosshair = PlayerHud.Crosshair;
local FreeMouse = PlayerHud.FreeMouse;
UserInputService.MouseIconEnabled = false; -- Default setting
Crosshair.Visible = true; -- Default setting
local function ToggleFreeMouse()
if not FreeMouse.Visible then
FreeMouse.Visible = true;
UserInputService.MouseIconEnabled = true;
Crosshair.Visible = false;
print("Mouse toggled on!");
else
FreeMouse.Visible = false;
UserInputService.MouseIconEnabled = false;
Crosshair.Visible = true;
print("Mouse toggled off!");
end
end
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F3 then
ToggleFreeMouse();
end
end)