Shiftlock script
Key RequiredUniversal

Shiftlock script

Universal Scriptboinoweeboinowee 1.2K views 16.1K executesUpdated Feb 17, 2026
Unrated
00
Lua Script•165 lines (5828 chars)
-- for PC it's left shift and for console it's buttonR3 which is just your joystick but you press on it



local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local GuiService = game:GetService("GuiService")
local UserGameSettings = UserSettings():GetService("UserGameSettings")

local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera

-- Constants for Native Look
local SHIFT_LOCK_OFF_IMAGE = "rbxasset://textures/ui/mouseLock_off@2x.png"
local SHIFT_LOCK_ON_IMAGE = "rbxasset://textures/ui/mouseLock_on@2x.png"
local SHIFT_LOCK_CURSOR = "rbxasset://textures/MouseLockedCursor.png"

-- Configuration
local TOGGLE_KEY_PC = Enum.KeyCode.LeftShift
local TOGGLE_BUTTON_CONSOLE = Enum.KeyCode.ButtonR3 -- Right Stick Click
local CAMERA_OFFSET = Vector3.new(1.75, 0, 0) -- The standard Roblox offset

-- State
local isShiftLocked = false
local isMobile = UserInputService.TouchEnabled and not UserInputService.MouseEnabled

-- UI Variables (Mobile Only)
local shiftLockGui, shiftLockButton

--------------------------------------------------------------------------------
-- CORE FUNCTIONS
--------------------------------------------------------------------------------

local function setShiftLockState(active)
    isShiftLocked = active
    
    local character = Player.Character
    local humanoid = character and character:FindFirstChild("Humanoid")
    
    if active then
        -- 1. Rotate Character with Camera (The Native Way)
        UserGameSettings.RotationType = Enum.RotationType.CameraRelative
        
        -- 2. Lock Mouse to Center
        UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
        
        -- 3. Set Custom Cursor
        UserInputService.MouseIcon = SHIFT_LOCK_CURSOR
        
        -- 4. Apply Camera Offset
        if humanoid then
            humanoid.CameraOffset = CAMERA_OFFSET
        end
        
        -- 5. Update Mobile UI
        if shiftLockButton then
            shiftLockButton.Image = SHIFT_LOCK_ON_IMAGE
        end
    else
        -- Reset everything to default
        UserGameSettings.RotationType = Enum.RotationType.MovementRelative
        UserInputService.MouseBehavior = Enum.MouseBehavior.Default
        UserInputService.MouseIcon = "" -- Resets to default arrow
        
        if humanoid then
            humanoid.CameraOffset = Vector3.new(0,0,0)
        end
        
        if shiftLockButton then
            shiftLockButton.Image = SHIFT_LOCK_OFF_IMAGE
        end
    end
end

local function toggleShiftLock()
    setShiftLockState(not isShiftLocked)
end

--------------------------------------------------------------------------------
-- MOBILE UI CREATION
--------------------------------------------------------------------------------

local function createMobileUI()
    if not isMobile then return end
    if Player.PlayerGui:FindFirstChild("ShiftLockGui") then return end

    local screenGui = Instance.new("ScreenGui")
    screenGui.Name = "ShiftLockGui"
    screenGui.ResetOnSpawn = false
    screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
    
    -- Container to match Roblox native button placement (Right side, near jump)
    local container = Instance.new("Frame")
    container.Name = "Container"
    container.Parent = screenGui
    container.BackgroundTransparency = 1
    container.Size = UDim2.new(0, 50, 0, 50)
    -- Position approximates standard Roblox mobile UI layout
    container.Position = UDim2.new(1, -120, 0.5, -40) 
    container.AnchorPoint = Vector2.new(1, 0.5)

    shiftLockButton = Instance.new("ImageButton")
    shiftLockButton.Name = "ShiftLockButton"
    shiftLockButton.Parent = container
    shiftLockButton.BackgroundTransparency = 1
    shiftLockButton.Size = UDim2.new(1, 0, 1, 0)
    shiftLockButton.Image = SHIFT_LOCK_OFF_IMAGE
    
    -- Touch Event
    shiftLockButton.Activated:Connect(toggleShiftLock)

    screenGui.Parent = Player.PlayerGui
    shiftLockGui = screenGui
end

--------------------------------------------------------------------------------
-- INPUT HANDLING
--------------------------------------------------------------------------------

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == TOGGLE_KEY_PC then
            toggleShiftLock()
        end
    elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
        if input.KeyCode == TOGGLE_BUTTON_CONSOLE then
            toggleShiftLock()
        end
    end
end)

--------------------------------------------------------------------------------
-- MAINTAIN STATE
--------------------------------------------------------------------------------

-- Ensure state persists if the character dies/respawns
Player.CharacterAdded:Connect(function(char)
    -- Small wait to ensure Humanoid is ready
    task.wait(0.1)
    if isShiftLocked then
        setShiftLockState(true) -- Re-apply offset and rotation
    end
end)

-- Constantly enforce mouse lock behavior in loop (prevents it from breaking when menu opens/closes)
RunService.RenderStepped:Connect(function()
    if isShiftLocked then
        -- Force the mode to stay active
        if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
            UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
        end
        -- Ensure RotationType stays correct (sometimes Roblox resets it)
        if UserGameSettings.RotationType ~= Enum.RotationType.CameraRelative then
            UserGameSettings.RotationType = Enum.RotationType.CameraRelative
        end
    end
end)

-- Initialize Mobile UI
if isMobile then
    createMobileUI()
end

Features & Information

It's literally a shiftlock script there's nothing to it
#Shiftlock#Mobile#Mobile shiftlock#Pc shiftlock#Universal

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts