Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game:GetService("Players").LocalPlayer
- local Mouse = Player:GetMouse()
- -- Create GUI
- local ScreenGui = Instance.new("ScreenGui")
- local ToggleButton = Instance.new("TextButton")
- ScreenGui.Parent = Player:WaitForChild("PlayerGui")
- ScreenGui.Name = "CamLockGUI"
- ToggleButton.Parent = ScreenGui
- ToggleButton.BackgroundColor3 = Color3.new(0, 0, 0)
- ToggleButton.Position = UDim2.new(0.5, -50, 0.9, -25)
- ToggleButton.Size = UDim2.new(0, 100, 0, 50)
- ToggleButton.Font = Enum.Font.SourceSans
- ToggleButton.Text = "Toggle CamLock"
- ToggleButton.TextColor3 = Color3.new(1, 1, 1)
- ToggleButton.TextSize = 14
- -- CamLock variables
- local CamLockActive = false
- local ClosestPlayer = nil
- -- Function to get closest player
- local function GetClosestPlayer()
- local closest = nil
- local shortestDistance = math.huge
- for _, v in pairs(game:GetService("Players"):GetPlayers()) do
- if v ~= Player and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
- local distance = (Player.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).magnitude
- if distance < shortestDistance then
- closest = v
- shortestDistance = distance
- end
- end
- end
- return closest
- end
- -- Toggle button functionality
- ToggleButton.MouseButton1Click:Connect(function()
- CamLockActive = not CamLockActive
- if CamLockActive then
- ToggleButton.Text = "CamLock: ON"
- else
- ToggleButton.Text = "CamLock: OFF"
- end
- end)
- -- Main loop
- game:GetService("RunService").RenderStepped:Connect(function()
- if CamLockActive then
- ClosestPlayer = GetClosestPlayer()
- 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)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement