Advertisement
rrixh

hanzujr

Sep 25th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1.  
  2. local Player = game:GetService("Players").LocalPlayer
  3. local Mouse = Player:GetMouse()
  4.  
  5. -- Create GUI
  6. local ScreenGui = Instance.new("ScreenGui")
  7. local ToggleButton = Instance.new("TextButton")
  8.  
  9. ScreenGui.Parent = Player:WaitForChild("PlayerGui")
  10. ScreenGui.Name = "CamLockGUI"
  11.  
  12. ToggleButton.Parent = ScreenGui
  13. ToggleButton.BackgroundColor3 = Color3.new(0, 0, 0)
  14. ToggleButton.Position = UDim2.new(0.5, -50, 0.9, -25)
  15. ToggleButton.Size = UDim2.new(0, 100, 0, 50)
  16. ToggleButton.Font = Enum.Font.SourceSans
  17. ToggleButton.Text = "Toggle CamLock"
  18. ToggleButton.TextColor3 = Color3.new(1, 1, 1)
  19. ToggleButton.TextSize = 14
  20.  
  21. -- CamLock variables
  22. local CamLockActive = false
  23. local ClosestPlayer = nil
  24.  
  25. -- Function to get closest player
  26. local function GetClosestPlayer()
  27.     local closest = nil
  28.     local shortestDistance = math.huge
  29.     for _, v in pairs(game:GetService("Players"):GetPlayers()) do
  30.         if v ~= Player and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
  31.             local distance = (Player.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).magnitude
  32.             if distance < shortestDistance then
  33.                 closest = v
  34.                 shortestDistance = distance
  35.             end
  36.         end
  37.     end
  38.     return closest
  39. end
  40.  
  41. -- Toggle button functionality
  42. ToggleButton.MouseButton1Click:Connect(function()
  43.     CamLockActive = not CamLockActive
  44.     if CamLockActive then
  45.         ToggleButton.Text = "CamLock: ON"
  46.     else
  47.         ToggleButton.Text = "CamLock: OFF"
  48.     end
  49. end)
  50.  
  51. -- Main loop
  52. game:GetService("RunService").RenderStepped:Connect(function()
  53.     if CamLockActive then
  54.         ClosestPlayer = GetClosestPlayer()
  55.         if ClosestPlayer and ClosestPlayer.Character and ClosestPlayer.Character:FindFirstChild("HumanoidRootPart") and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then         Player.Character.HumanoidRootPart.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, ClosestPlayer.Character.HumanoidRootPart.Position)
  56.         end
  57.     end
  58. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement