I wish to create a weapon which allows the player to aim, but when aimed I wish for the sensitivity of the mouse to lower so that they can be more accurate. What is the best way of changing mouse sensitivity in a local script? Any help and or suggestions would be appreciated.
Please always check devforum for related questions before posting! This is a huge help on your sides as It can help getting support before asking a developer and/or waiting for a response!
I have found a post relating mouse sensitivity, this is achieved by:
double PlayerMouse:GetSensitivity()
void PlayerMouse:SetSensitivity(double sensitivity) – where ‘sensitivity’ is locked between ‘0’ and ‘2’ (2 for double speed)
In double sensitivity
you would define a number from 0 to 2 to change the sensitivity.
Please inform me if this is not what your looking for!
What does double and void do in this section?
void
and double
are the datatypes that the functions return.
void
means it doesn’t return any values
double
means it that it returns a number.
Alright perfect, and where would I find player mouse. I am using a local script and have used local Mouse = Player:GetMouse(), but this dosnt seem to work as it errors:
I am using this local script inside of a tool.
Remove the 2 double
s and void
, they’re just used in the documentation to show what they return/what it should be.
I have corrected this but keep getting the error SetSensitivity is not a valid member of PlayerMouse
Did you define the player? It would be
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
If this does not work can you show an image of your error please? Please show up your whole script with the error.
After checking the api-reference, I didn’t find this function so I guess there’s no such thing.
I did however, remember about UserInputService’s MouseDeltaSensitivity which can be set to a number between 0 and 2.
This is a feature request. It has not been implemented as a part of the official API – it is simply a suggestion made by a community developer.
UserInputService.MouseDeltaSensitivity = 10, This works perfectly thank you.
Also, if you want to systematically decrease the field of view, you can try using TweenService on the FOV value. You can also use a for loop, like so:
for fov = start_value, end_value, increment do --increment should be negative if you're decreasing
camera.FieldOfView = fov
end
I will be sure to implement this thank you