Untitled conversation
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local mouseLockLabel = script.Parent
local mouseLock = nil
local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
local MaxLength = 900000
local EnabledOffset = CFrame.new(1.7, 0, 0)
local DisabledOffset = CFrame.new(-1.7, 0, 0)
local function shiftLock(active)
local Character = Player.Character
if not Character or not Character:FindFirstChild("Humanoid") then return end
local hum = Character.Humanoid
local root = hum.RootPart
if active then
hum.CameraOffset = Vector3.new(1.75, 0, 0)
hum.AutoRotate = false
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, y = CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, y, 0)
end)
Mouse.Icon = SHIFT_LOCK_CURSOR
mouseLockLabel.Image = SHIFT_LOCK_ON
else
hum.CameraOffset = Vector3.new(0, 0, 0)
RunService:UnbindFromRenderStep("ShiftLock")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
hum.AutoRotate = true
Mouse.Icon = "http://www.roblox.com/asset/?id=7025168168"
mouseLockLabel.Image = SHIFT_LOCK_OFF
end
end
local function shiftLockSwitcher()
if mouseLock then
mouseLock:Disconnect()
mouseLock = nil
shiftLock(false)
CurrentCamera.CFrame = CurrentCamera.CFrame * DisabledOffset
else
mouseLock = RunService.Heartbeat:Connect(function()
local Character = Player.Character
if Character and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("HumanoidRootPart") then
local hum = Character.Humanoid
local root = Character.HumanoidRootPart
hum.AutoRotate = false
root.CFrame = CFrame.new(
root.Position,
Vector3.new(
CurrentCamera.CFrame.LookVector.X * MaxLength,
root.Position.Y,
CurrentCamera.CFrame.LookVector.Z * MaxLength
)
)
CurrentCamera.CFrame = CurrentCamera.CFrame * EnabledOffset
CurrentCamera.Focus = CFrame.fromMatrix(
CurrentCamera.Focus.Position,
CurrentCamera.CFrame.RightVector,
CurrentCamera.CFrame.UpVector
) * EnabledOffset
end
end)
shiftLock(true)
end
end
mouseLockLabel.MouseButton1Click:Connect(shiftLockSwitcher)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockSwitcher()
end
end)
hello. whenever shift lock is enabled, and player goes inside of first person (by zooming in), the camera still stays in the moved position, when instead, it should be like shiftlock isn't enabled. can you fix that?
Here's the modified code with the necessary fixes to address the first-person camera issue and the exponential movement bug:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local mouseLockLabel = script.Parent
local mouseLock = nil
local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
local MaxLength = 900000
local EnabledOffset = CFrame.new(1.7, 0, 0)
local DisabledOffset = CFrame.new(-1.7, 0, 0)
local function shiftLock(active)
local Character = Player.Character
if not Character or not Character:FindFirstChild("Humanoid") then return end
local hum = Character.Humanoid
local root = hum.RootPart
if active then
hum.CameraOffset = Vector3.new(1.75, 0, 0)
hum.AutoRotate = false
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, y = CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, y, 0)
end)
Mouse.Icon = SHIFT_LOCK_CURSOR
mouseLockLabel.Image = SHIFT_LOCK_ON
else
hum.CameraOffset = Vector3.new(0, 0, 0)
RunService:UnbindFromRenderStep("ShiftLock")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
hum.AutoRotate = true
Mouse.Icon = "http://www.roblox.com/asset/?id=7025168168"
mouseLockLabel.Image = SHIFT_LOCK_OFF
end
end
local function shiftLockSwitcher()
if mouseLock then
mouseLock:Disconnect()
mouseLock = nil
shiftLock(false)
CurrentCamera.CFrame = CurrentCamera.CFrame * DisabledOffset
else
-- Set initial camera position once
CurrentCamera.CFrame = CurrentCamera.CFrame * EnabledOffset
CurrentCamera.Focus = CFrame.fromMatrix(
CurrentCamera.Focus.Position,
CurrentCamera.CFrame.RightVector,
CurrentCamera.CFrame.UpVector
) * EnabledOffset
mouseLock = RunService.Heartbeat:Connect(function()
local Character = Player.Character
if Character and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("HumanoidRootPart") then
local hum = Character.Humanoid
local root = Character.HumanoidRootPart
-- Check if in first-person based on FieldOfView
local FOV = CurrentCamera.FieldOfView
local inFirstPerson = FOV > 100
if inFirstPerson then
hum.CameraOffset = Vector3.new(0, 0, 0)
else
hum.CameraOffset = Vector3.new(1.75, 0, 0)
end
hum.AutoRotate = false
root.CFrame = CFrame.new(
root.Position,
Vector3.new(
CurrentCamera.CFrame.LookVector.X * MaxLength,
root.Position.Y,
CurrentCamera.CFrame.LookVector.Z * MaxLength
)
)
end
end)
shiftLock(true)
end
end
mouseLockLabel.MouseButton1Click:Connect(shiftLockSwitcher)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockSwitcher()
end
end)
Key Changes:
Removed Exponential Movement:
First-Person Detection:
FieldOfView property (assumes first-person has FOV > 100).CameraOffset to 0 when in first-person to reset the camera position.Maintained Core Functionality:
This should resolve the camera staying shifted in first-person and the exponential movement issue.