Could you make it so the script doesn't mess with the players sensitivity? as that is a…
- User
Could you make it so the script doesn't mess with the players sensitivity? as that is a MAJOR no-no in making Roblox games
Assistant
You are absolutely right! Apologies, using a fixed sensitivity value in a custom camera script is indeed bad practice as it overrides the player's personal preference set in the Roblox settings menu.
The fix is simple: instead of using a hardcoded
SENSITIVITYconstant in the script, we need to read and use the player's actualMouseSensitivityproperty. This property automatically reflects the value the player sets in the Roblox escape menu.Here's the updated script that respects the player's sensitivity setting:
📜 Updated LocalScript:
OverTheShoulderCamera.luaPlace this in StarterPlayer > StarterPlayerScripts as a LocalScript.
local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer local camera = workspace.CurrentCamera local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local rootPart = character:WaitForChild("HumanoidRootPart") -- Settings local CAMERA_OFFSET = Vector3.new(2, 1.5, 6) -- Right, Up, Back (slightly to the right of the player) local MAX_Y_ANGLE = math.rad(80) local MIN_Y_ANGLE = math.rad(-80) -- Internal local cameraAngleX = 0 local cameraAngleY = 0 local isRightMouseDown = false -- Disable default camera and controls camera.CameraType = Enum.CameraType.Scriptable UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter -- Lock mouse on input (Optional: If you want the mouse always locked, remove this) UserInputService.InputBegan:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.MouseButton2 then isRightMouseDown = true UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter end end) UserInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then isRightMouseDown = false end end) -- Mouse movement UserInputService.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseMovement then local delta = input.Delta -- *** MODIFIED HERE: Use player.MouseSensitivity instead of a fixed value *** cameraAngleX -= delta.X * player.MouseSensitivity cameraAngleY = math.clamp(cameraAngleY - delta.Y * player.MouseSensitivity, MIN_Y_ANGLE, MAX_Y_ANGLE) end end) -- Update camera and character rotation RunService.RenderStepped:Connect(function() if not character or not rootPart then return end -- Calculate camera CFrame local startCFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, cameraAngleX, 0) * CFrame.Angles(cameraAngleY, 0, 0) local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(CAMERA_OFFSET)) local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(CAMERA_OFFSET.X, CAMERA_OFFSET.Y, -10000)) camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position) -- Force character to face the OPPOSITE of the camera direction (inverted look vector) local lookVector = Vector3.new(math.sin(cameraAngleX), 0, math.cos(cameraAngleX)).Unit -- Original look vector local invertedLookVector = -lookVector -- Invert it to face "behind" rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + invertedLookVector) -- Character faces the inverted direction end)✅ Key Changes
- Removed
SENSITIVITYconstant: The linelocal SENSITIVITY = 0.002is gone. - Using
player.MouseSensitivity: In theInputChangedfunction, where the camera angles are updated based on mouse delta,* SENSITIVITYhas been replaced with* player.MouseSensitivity.
Now, the speed at which the camera rotates in response to mouse movement will scale correctly with whatever sensitivity the player has set in their game settings. This provides a much better user experience.
Thanks for catching that!
- Removed
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.