Answered by
8 years ago Edited 8 years ago
I have a script that does this that I edited a while ago, you can use this (:
01 | local player = game.Players.LocalPlayer |
02 | repeat wait() until player.Character |
03 | local char = player.Character |
04 | local hrp = char:WaitForChild( "HumanoidRootPart" ) |
05 | local cam = game.Workspace.CurrentCamera |
07 | cam.CameraType = Enum.CameraType.Scriptable |
09 | game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.LockCenter |
16 | game:GetService( "RunService" ).RenderStepped:wait() |
17 | hrp.CFrame = CFrame.new(hrp.Position) * CFrame.Angles( 0 , x, 0 ) |
18 | cam.CoordinateFrame = hrp.CFrame * CFrame.Angles(y, 0 , 0 ) * CFrame.new( 2 , 2 , 12 ) |
22 | function MouseMove(name, state, inputObject) |
23 | x = x + (-inputObject.Delta.x / 100 ) |
24 | y = y + (-inputObject.Delta.y / 100 ) |
32 | script.Lock.Changed:connect( function () |
33 | if script.Lock.Value = = false then |
34 | print ( 'Mouse Unlocked' ) |
35 | game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.Default |
37 | elseif script.Lock.Value = = true then |
38 | game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.LockCenter |
44 | game:GetService( "ContextActionService" ):BindActionToInputTypes( "MouseMove" , MouseMove, false , Enum.UserInputType.MouseMovement) |
-Just put this inside of a local script and put it in StarterPack.
-Add a BoolValue under the script and name it Lock.
-Add another LocalScript and put it under the main one and add this code
01 | player = script.Parent.Parent.Parent |
02 | plr = game.Players.LocalPlayer |
03 | repeat wait() until plr.Character |
05 | local Player = plr.Character |
08 | mouse.KeyDown:connect( function (key) |
12 | if plr.Backpack.MouseLock.Lock.Value = = true then |
13 | plr.Backpack.MouseLock.Lock.Value = false |
14 | elseif plr.Backpack.MouseLock.Lock.Value = = false then |
15 | plr.Backpack.MouseLock.Lock.Value = true |
This should work perfectly. The only bug is you won't be able to move your character freely. This is the only problem I've found with my method I've been trying to fix. I hope this helps.
Closed as Not Constructive by Link150, User#11440, and TheHospitalDev
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?