Problem with shoulder camera script

Hello everyone, I need help with this camera script:

local uis = game:GetService("UserInputService")
local isMobile = uis.TouchEnabled

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")

local x = 0
local y = 0

local offset = Vector3.new(3, 3, 10)

local enabled = script.Enabled

uis.InputChanged:Connect(function(input, processed)
	if enabled.Value == true then
		if processed then return end
		if not isMobile then
			if input.UserInputType == Enum.UserInputType.MouseMovement then
				x = x - input.Delta.X
				y = math.clamp(y - input.Delta.Y * 0.4, -75, 75)
				
				hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
			end
		end
	end
end)


game:GetService("RunService").RenderStepped:Connect(function()
	if enabled.Value == true then
		if not isMobile then
			uis.MouseBehavior = Enum.MouseBehavior.LockCenter

			local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
			local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
			local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))

			camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
		end
	end
end)

When I change the value to false to disable it, if the player was walking it stays walking even if I don’t press w. And if the player was not walking when I changed the value to false then it can’t walk anymore.

No output errors.

Thanks for reading.

1 Like