local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local ContextActionService = game:GetService("ContextActionService") local LocalPlayer = Players.LocalPlayer local Camera = workspace.CurrentCamera -- 1. Create ScreenGui automatically local playerGui = LocalPlayer:WaitForChild("PlayerGui") local screenGui = Instance.new("ScreenGui") screenGui.Name = "ShiftLockGui" screenGui.ResetOnSpawn = false screenGui.Parent = playerGui -- 2. Create Shift Lock Toggle Button (Exact Icon & Style) local shiftButton = Instance.new("ImageButton") shiftButton.Name = "ShiftLockButton" shiftButton.Size = UDim2.new(0, 50, 0, 50) shiftButton.Position = UDim2.new(1, -70, 0.5, -25) -- Middle-right screen area shiftButton.BackgroundTransparency = 1 shiftButton.Image = "rbxasset://textures/ui/mouseLock_off.png" shiftButton.Parent = screenGui -- 3. Create Center Crosshair Icon local crosshair = Instance.new("ImageLabel") crosshair.Name = "ShiftLockCrosshair" crosshair.Size = UDim2.new(0, 32, 0, 32) crosshair.AnchorPoint = Vector2.new(0.5, 0.5) crosshair.Position = UDim2.new(0.5, 0, 0.5, 0) crosshair.BackgroundTransparency = 1 crosshair.Image = "rbxasset://textures/MouseLockedCursor.png" crosshair.Visible = false crosshair.Parent = screenGui -- Textures local TEXTURE_OFF = "rbxasset://textures/ui/mouseLock_off.png" local TEXTURE_ON = "rbxasset://textures/ui/mouseLock_on.png" local isShiftLocked = false -- Toggle function local function setShiftLock(enabled) isShiftLocked = enabled if isShiftLocked then shiftButton.Image = TEXTURE_ON crosshair.Visible = true UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter else shiftButton.Image = TEXTURE_OFF crosshair.Visible = false UserInputService.MouseBehavior = Enum.MouseBehavior.Default end end -- Render loop for Camera & Character behavior RunService.RenderStepped:Connect(function() local character = LocalPlayer.Character if not character then return end local humanoid = character:FindFirstChildOfClass("Humanoid") local rootPart = character:FindFirstChild("HumanoidRootPart") if isShiftLocked and humanoid and rootPart and humanoid.Health > 0 then UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter humanoid.AutoRotate = false -- Rotate player to face camera direction local cameraCFrame = Camera.CFrame local lookVector = Vector3.new(cameraCFrame.LookVector.X, 0, cameraCFrame.LookVector.Z) if lookVector.Magnitude > 0 then rootPart.CFrame = CFrame.lookAt(rootPart.Position, rootPart.Position + lookVector) end -- Shoulder camera offset Camera.CFrame = cameraCFrame * CFrame.new(1.75, 0.5, 0) else if humanoid then humanoid.AutoRotate = true end end end) -- Keyboard Input (Left Shift) ContextActionService:BindAction("ToggleShiftLock", function(actionName, inputState) if inputState == Enum.UserInputState.Begin then setShiftLock(not isShiftLocked) end return Enum.ContextActionResult.Pass end, false, Enum.KeyCode.LeftShift) -- Button click support (Mobile & PC Mouse) shiftButton.MouseButton1Click:Connect(function() setShiftLock(not isShiftLocked) end) -- Reset state on respawn LocalPlayer.CharacterAdded:Connect(function() setShiftLock(false) end)