local Players = game:GetService("Players") local player = Players.LocalPlayer local camera = workspace.CurrentCamera local RunService = game:GetService("RunService") local StarterGui = game:GetService("StarterGui") local UIS = game:GetService("UserInputService") -- Notification StarterGui:SetCore("SendNotification", { Title = "Camlock ON", Text = "Locking camera to NPC's Neck", Duration = 3 }) -- GUI local screenGui = Instance.new("ScreenGui", game:GetService("CoreGui")) screenGui.Name = "Camlock_GUI" local button = Instance.new("TextButton") button.Name = "CamlockToggle" button.Size = UDim2.new(0, 150, 0, 50) button.Position = UDim2.new(1, -155, 0.1, -25) -- Button positioned at the top-right corner button.BackgroundColor3 = Color3.new(0, 0, 0) button.TextColor3 = Color3.new(1, 1, 1) button.Text = "ᴄᴀᴍʟᴏᴄᴋ: ᴏɴ" button.Font = Enum.Font.SourceSans button.TextScaled = true button.TextSize = 30 button.Parent = screenGui local corner = Instance.new("UICorner", button) corner.CornerRadius = UDim.new(0, 12) -- Variables for dragging local dragging = false local dragInput, dragStart, startPos -- Function to update the position of the button while dragging local function update(input) local delta = input.Position - dragStart local newPosition = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y) -- Smoothly updating button position button.Position = newPosition end -- Detect mouse button down button.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then dragging = true dragStart = input.Position startPos = button.Position input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then dragging = false end end) end end) -- Detect mouse movement and update button position button.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseMovement then dragInput = input end end) game:GetService("UserInputService").InputChanged:Connect(function(input) if dragging and input == dragInput then update(input) end end) -- Find closest NPC and lock onto their neck local function getClosestNPC() local closest, shortestDist = nil, math.huge for _, obj in ipairs(workspace:GetDescendants()) do if obj:IsA("Model") and obj ~= player.Character then local hum = obj:FindFirstChildWhichIsA("Humanoid") local neck = obj:FindFirstChild("Neck") or obj:FindFirstChild("Head") if hum and neck and hum.Health > 0 then -- Ensure it's not a player local isPlayer = false for _, plr in ipairs(Players:GetPlayers()) do if plr.Character == obj then isPlayer = true break end end if not isPlayer then local dist = (neck.Position - camera.CFrame.Position).Magnitude if dist < shortestDist then shortestDist = dist closest = neck end end end end end return closest end -- Camlock Logic local camlockEnabled = false local camlockLoop button.MouseButton1Click:Connect(function() camlockEnabled = not camlockEnabled button.Text = camlockEnabled and "ᴄᴀᴍʟᴏᴄᴋ: ᴏɴ" or "ᴄᴀᴍʟᴏᴄᴋ: ᴏғғ" if camlockEnabled then camlockLoop = RunService.RenderStepped:Connect(function() local target = getClosestNPC() if target then camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position) end end) else if camlockLoop then camlockLoop:Disconnect() end end end)