Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I lock a FPS camera and unlock it?

Asked by 9 years ago

I'm trying to manipulate the roblox camera to make a FPS. I want the player to be forced to stay in First Person Mode, but i want them to be able to unlock their mouse in FPS mode with a key like for example "Alt". I press Alt and my mouse is free to move. I press Alt again and it locks it self to the center of the screen. This would be useful to click GUIs and Etc in First Person Mode.

I have the basic FPS script:

game.Players.PlayerAdded:connect(function(player)
player.CameraMode = Enum.CameraMode.LockFirstPerson
end)

Please reply/help me! Thank you!

2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

LocalScript

local Player=game.Players.LocalPlayer 
local Mode=false

Player:GetMouse().KeyDown:connect(function(key) --Getting PlayerMouse, KeyDown event
    if key==3 or 4 then --Left or Right 'alt' keys
        Mode=not Mode 
        if Mode==true then -- if mode equals true
            Player.CameraMode=Enum.CameraMode.LockFirstPerson
        elseif Mode==false then --if mode equals false
            Player.CameraMode=Enum.CameraMode.Classic
        end
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

i recommend you use "CameraMaxZoomDistance" instead of LockFirstPerson because is a bit unpredictable(In local script)

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
game.Players.PlayerAdded:connect(function(player)
    player.CameraMaxZoomDistance = 0
end)
-- and also have another function that binds it
    Mouse.KeyDown:connect(function(key)
        if key ==  "y" then
            --do something
        end

If you want to learn some other things read this : http://wiki.roblox.com/index.php?title=Taking_keyboard_input

Answer this question