Hey developers,
How do I make the roblox camera lock on first person disable when I press a keybind.
I did try to search on google but didn’t find any.
Still don’t understand on what I mean? Ok it’s like this, your in first person and when you press the latter e on your keyboard (example) it will open a gui and your crusor won’t stuck at the middle of the screen. It’s like your crusor is free in first person.
Some game have this type of thing but without pressing keybind, like tds (tower defense simulator)
Yes I know how to set first person, I mean like it makes the crusor free in first person when I press a keybind
Could be to do something with UserInputService.MouseBehavior - hence, whenever you set their CameraMode, change the behaviour to Default
when E is pressed, otherwise LockCenter
.
To know when a keybind is pressed, read UserInputService.InputBegan.
I’m bad at scripting and I don’t even know how do that work😅 You got any youtube video or forum post that is same with this kind lf problem? The camera is like you know the state of anarchy game? That when you press tab it will release your crusor in first person and the crusor is free to move arround
Right, I’ll be able to help soon, got a class to go to.
hello!
Gui Text Buttons have a property called “modals” which let your camera move freely if you are in first person.
Here is a link to a small article about ‘modals’ :GuiButton | Roblox Creator Documentation
Hope this helps!
Alr, take your time😊 Good luck with it
Thanks, I will try to understand it😊
Alright, you’d want to highlight the bool Modal
underneath the TextButton
properties as @ELECTRIKKILLE stated - allowing you to gain control over your mouse unless if right-click is held.
--[ Variables ]
local UIP = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
--[ UI Paths ]
local ui = script:FindFirstChildWhichIsA("ScreenGui")
local frame = ui:FindFirstChildWhichIsA("Frame")
local button = frame:FindFirstChildWhichIsA("TextButton")
--[ First Person ]
local lockFirstPerson = Enum.CameraMode.LockFirstPerson
plr.CameraMode = lockFirstPerson
--[ Listening to E keybind ]
UIP.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then --if E pressed then
button.Modal = not button.Modal --reverse the bool (if true, then false)
end
end)
Alternatively, you could not render the character, but I presume the solution above is the most preferable one as you’re only needing it for UI.
Unfortunately, MouseBehavior
can’t be used, hence Roblox always wants to keep it .LockCenter
whenever the CameraMode is locked in first person, defeatable by RunService
which causes performance issues.
3 years later, and the soluion is that you put a frame that fills the entire player’s screen and then toggle modal to true
Yea but I feel like this has been a thing for quite a while now but I might be wrong, asides thats it works perfectly!