I've Searched Every To Find How To Lock the Mouse So The Player Is In ThirdPerson And Has Their Mouse Locked.
UserInputService
has a special function to change the behavior of the mouse.
MouseBehavior States:
Default:0
LockCenter:1
LockCurrentPosition:2
Code:
local UserInputService = game:GetService("UserInputService") while true do --Loops due the CoreMenu resetting the state when you pause the game wait() UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Changes the behavior to 'LockCenter' end
http://wiki.roblox.com/index.php?title=API:Class/UserInputService/MouseBehavior
I have a script that does this that I edited a while ago, you can use this (:
local player = game.Players.LocalPlayer repeat wait() until player.Character local char = player.Character local hrp = char:WaitForChild("HumanoidRootPart") local cam = game.Workspace.CurrentCamera print("Ready") cam.CameraType = Enum.CameraType.Scriptable wait() game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter local x = 0 local y = 0 spawn(function() while true do game:GetService("RunService").RenderStepped:wait() hrp.CFrame = CFrame.new(hrp.Position) * CFrame.Angles(0, x, 0) cam.CoordinateFrame = hrp.CFrame * CFrame.Angles(y, 0, 0) * CFrame.new(2, 2, 12) end end) function MouseMove(name, state, inputObject) x = x + (-inputObject.Delta.x / 100) y = y + (-inputObject.Delta.y / 100) if y > 1.5 then y = 1.5 elseif y < -1.5 then y = -1.5 end end script.Lock.Changed:connect(function() if script.Lock.Value == false then print('Mouse Unlocked') game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default --cam.CameraType = Enum.CameraType.Follow elseif script.Lock.Value == true then game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter --cam.CameraType = Enum.CameraType.Scriptable print('Mouse Locked') end end) 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
player = script.Parent.Parent.Parent plr = game.Players.LocalPlayer repeat wait() until plr.Character mouse = plr:GetMouse() local Player = plr.Character mouse.KeyDown:connect(function(key) key = key:lower() if key == "c" then wait(.2) if plr.Backpack.MouseLock.Lock.Value == true then plr.Backpack.MouseLock.Lock.Value = false elseif plr.Backpack.MouseLock.Lock.Value == false then plr.Backpack.MouseLock.Lock.Value = true end end end)
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?