Un-Shift lock when holding left alt not working

Use ``` or blockcode to format your code.

1 Like

Here I formatted it. Can you also help me with my problem?

Do you want to recreate shiftlock or just change the keybind?

1 Like
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

RunService:BindToRenderStep("MouseLock", Enum.RenderPriority.Last.Value + 1, function()
	UserInputService.InputBegan:Connect(function(Input, GPE)
		if GPE then return end
		if UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) then
			UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		elseif not UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) then
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

RunService:BindToRenderStep("ForceShiftlock", Enum.RenderPriority.Camera.Value + 1, function()
	UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative
	local currentCamera = workspace.CurrentCamera
	if not currentCamera then return end
	if (currentCamera.Focus.Position - currentCamera.CFrame.Position).Magnitude >= 0.99 then
		currentCamera.CFrame = currentCamera.CFrame*CFrame.new(1.75, 0, 0)
		currentCamera.Focus = CFrame.fromMatrix(currentCamera.Focus.Position, currentCamera.CFrame.RightVector, currentCamera.CFrame.UpVector)*CFrame.new(1.75, 0, 0)

heres the formatted code, now its easier to read

1 Like

I just want it so your in shift lock all of the time and if you hold left alt it goes out of shift lock and when you let go of the left alt key it goes back into shift lock.

Alright then, try this tutorial. It might help. If it doesn’t I’ll make a custom script real quick.


I can’t find the camera module

Oh, that’s quite simple to do! Just playtest the game and search for “CameraModule.”

1 Like

Nope, Doesn’t work. It just does the offset and the thing in the camera module script doesn’t do anything.

1 Like

Alright, I’ll create a force shiftlock script, in the mean time - use this script to toggle your shiftlock on and off with a custom keybind. Assuming that you’re trying to change that as well.

script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController"):WaitForChild("BoundKeys").Value = "LeftAlt"
1 Like

Where do I put that line of code?

LocalScripts are usually placed in StarterPlayer or StarterGUI. It depends on what they’re meant to preform, if they’re for the character - StarterCharacterScripts, but our case, it’s used for the player - meaning, you place it in StarterPlayerScripts. :smile:

1 Like

Alright then, I managed to get something similar to shiftlock and what you wanted, though it’s not yet ready. Read both scripts and try to fully modify it as you desire. Anyway, here’s the place. Example.rbxl (22.4 KB)

1 Like

On the last line there is a variable called handleMovement but you didn’t specify what it is

Oh, I made a mistake there, re-write it like so.

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraOffset = Vector3.new(2, 2, 8)
local player = Players.LocalPlayer
	local humanoid = character:WaitForChild("Humanoid")
	local rootPart = character:WaitForChild("HumanoidRootPart")
	humanoid.AutoRotate = false
	local cameraAngleX = 0
	local cameraAngleY = 0
	local function playerInput(actionName, inputState, inputObject)
		-- Calculate camera/player rotation on input change
		if inputState == Enum.UserInputState.Change then
			cameraAngleX = cameraAngleX - inputObject.Delta.X
			-- Reduce vertical mouse/touch sensitivity and clamp vertical axis
			cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
			-- Rotate root part CFrame by X delta
			rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, math.rad(-inputObject.Delta.X), 0)
	ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
		if camera.CameraType ~= Enum.CameraType.Scriptable then
			camera.CameraType = Enum.CameraType.Scriptable
		local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
		local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
		local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
		camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
local function focusControl(actionName, inputState, inputObject)
	-- Lock and hide mouse icon on input began
	if inputState == Enum.UserInputState.Begin then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		UserInputService.MouseIconEnabled = false
		ContextActionService:UnbindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)

Another problem, When you press alt the mouse is invisible and the camera doesn’t move right

Use Mouse.Cursor for the cursor.

And what about the camera that doesn’t move right?

1 Like

Nevermind- Mouse.Cursor would be useless. Change this:
Currently working on fixing the camera.

1 Like

Ik I already did this. Just need the camera to work.

1 Like