Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

is there a way to decrease the player's camera sensitivity as they hold the right mouse button?

i am making a sniper system in my game and to do it i need to slow down the sensitivity, is there a value i can change for this?

1 answer

✓ Accepted answer

UserInputService.MouseDeltaSensivity:

local UserInputService = game:GetService("UserInputService")

UserInputService.MouseDeltaSensivity = 0.5 -- 2 times slower

The default sensivity is always 1 and is a multiplier of user's sensivity in his game settings. You can then use InputBegan and InputEnded to detect when user holds right mouse button:

local RIGHT_MOUSE_BUTTON = Enum.UserInputType.MouseButton2
local SNIPER_SENSIVITY = 0.5

local UserInputService = game:GetService("UserInputService")

local right_mouse_button_down = false

local function right_mouse_button_down_updated()
	if right_mouse_button_down then
		UserInputService.MouseDeltaSensitivity = SNIPER_SENSIVITY
	else
		UserInputService.MouseDeltaSensitivity = 1
	end
end

local function on_input_ended(input)
	if input.UserInputType == RIGHT_MOUSE_BUTTON then
		right_mouse_button_down = false
		right_mouse_button_down_updated()
	end
end

local function on_input_began(input)
	if input.UserInputType == RIGHT_MOUSE_BUTTON then
		right_mouse_button_down = true
		right_mouse_button_down_updated()
	end
end

UserInputService.InputBegan:Connect(on_input_began)
UserInputService.InputEnded:Connect(on_input_ended)

1 comment

0

this worked, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.