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

How Do I Make The Player's Mouse Lock? [closed]

Asked by 8 years ago

I've Searched Every To Find How To Lock the Mouse So The Player Is In ThirdPerson And Has Their Mouse Locked.

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?

2 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

UserInputServicehas a special function to change the behavior of the mouse.

MouseBehavior States:

Default:0
LockCenter:1
LockCurrentPosition:2

Code:

1local UserInputService = game:GetService("UserInputService")
2 
3while true do --Loops due the CoreMenu resetting the state when you pause the game
4    wait()
5    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Changes the behavior to 'LockCenter'
6end

http://wiki.roblox.com/index.php?title=API:Class/UserInputService/MouseBehavior

0
How Do You Make It Change Back So You Can Move It MentalHealthIssues 5 — 8y
0
You could probably add a function and a variable that will be set true or false, depending whether it is true or false it would change the state. UniversalDreams 205 — 8y
0
My code can do this, I needed mines to do that too. I will edit my answer to suit your needs StoIid 364 — 8y
Ad
Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago
Edited 8 years ago

I have a script that does this that I edited a while ago, you can use this (:

01local player = game.Players.LocalPlayer
02repeat wait() until player.Character
03local char = player.Character
04local hrp = char:WaitForChild("HumanoidRootPart")
05local cam = game.Workspace.CurrentCamera
06print("Ready")
07cam.CameraType = Enum.CameraType.Scriptable
08wait()
09game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
10 
11local x = 0
12local y = 0
13 
14spawn(function()
15    while true do
View all 44 lines...

-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

01player = script.Parent.Parent.Parent
02plr = game.Players.LocalPlayer
03repeat wait() until plr.Character
04mouse = plr:GetMouse()
05local Player = plr.Character
06 
07 
08mouse.KeyDown:connect(function(key)
09    key = key:lower()
10    if key == "c" then
11    wait(.2)
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
16 
17end
18end
19end)

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.

0
The Script Is Kinda Long MentalHealthIssues 5 — 8y
0
What do you mean? ;-; Does it not work (I'm sure it does) or do you not understand it? StoIid 364 — 8y
0
Yes, I have a question. How does the script work!?! User#11440 120 — 8y
0
I'm Just A Noob Scripter I Don't Get It MentalHealthIssues 5 — 8y
View all comments (4 more)
0
It works by first locking your mouse, then readjusting it to the CFrame located in line 18. After that the loop basically just makes your character face whever your mouse is pointing to avoid glitching. StoIid 364 — 8y
0
I Don't Know What That is MentalHealthIssues 5 — 8y
0
I Will Use it Then MentalHealthIssues 5 — 8y
0
If I ever fix the bug, I will give you the updated code. StoIid 364 — 8y