benxogian

Untitled

Dec 27th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local camera = workspace.CurrentCamera
  3. local playerGui = player:WaitForChild("PlayerGui")
  4.  
  5. -- Default values for smoothness and prediction
  6. local smoothSpeed = 0.9 -- Default smoothness
  7. local predictionValue = 0.150 -- Default prediction
  8.  
  9. -- Variables to manage lock-on state
  10. local isLockedOn = false
  11. local lockedPlayer = nil
  12.  
  13. -- Create the GUI when the player's character is added
  14. local function createGUI()
  15. -- Create a screen GUI for the buttons
  16. local screenGui = Instance.new("ScreenGui")
  17. screenGui.Parent = playerGui
  18.  
  19. -- Create a button to lock on with a custom background image
  20. local lockButton = Instance.new("TextButton")
  21. lockButton.Size = UDim2.new(0, 100, 0, 50)
  22. lockButton.Position = UDim2.new(1, -110, 0, 10) -- Button positioned at the top-right corner
  23. lockButton.Text = "Lock On"
  24. lockButton.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
  25. lockButton.BackgroundTransparency = 1 -- Make background transparent
  26. lockButton.Parent = screenGui
  27.  
  28. -- Set the button's background image
  29. local imageLabel = Instance.new("ImageLabel")
  30. imageLabel.Parent = lockButton
  31. imageLabel.Size = UDim2.new(1, 0, 1, 0)
  32. imageLabel.BackgroundTransparency = 1
  33. imageLabel.Image = "https://pin.it/3C4XClbjH" -- Set image to the URL provided
  34. imageLabel.ScaleType = Enum.ScaleType.Stretch
  35.  
  36. -- Create a new button for showing settings
  37. local settingsButton = Instance.new("TextButton")
  38. settingsButton.Size = UDim2.new(0, 100, 0, 50)
  39. settingsButton.Position = UDim2.new(0.5, -50, 0, 10) -- Button just below the "Lock On" button
  40. settingsButton.Text = "Settings"
  41. settingsButton.BackgroundColor3 = Color3.fromRGB(0, 0, 255)
  42. settingsButton.BackgroundTransparency = 1 -- Make background transparent
  43. settingsButton.Parent = screenGui
  44.  
  45. -- Create a frame for the settings tab (hidden by default)
  46. local settingsFrame = Instance.new("Frame")
  47. settingsFrame.Size = UDim2.new(0, 200, 0, 60)
  48. settingsFrame.Position = UDim2.new(0.5, -100, 0, 70) -- Positioned below the settings button
  49. settingsFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50) -- Dark background
  50. settingsFrame.Parent = screenGui
  51. settingsFrame.Visible = false -- Start with the settings frame hidden
  52.  
  53. -- Smoothness label and textbox
  54. local smoothnessLabel = Instance.new("TextLabel")
  55. smoothnessLabel.Size = UDim2.new(0, 100, 0, 30)
  56. smoothnessLabel.Position = UDim2.new(0, 10, 0, 10)
  57. smoothnessLabel.Text = "Smoothness:"
  58. smoothnessLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  59. smoothnessLabel.Parent = settingsFrame
  60.  
  61. local smoothnessBox = Instance.new("TextBox")
  62. smoothnessBox.Size = UDim2.new(0, 80, 0, 30)
  63. smoothnessBox.Position = UDim2.new(0, 110, 0, 10)
  64. smoothnessBox.Text = tostring(smoothSpeed)
  65. smoothnessBox.Parent = settingsFrame
  66.  
  67. -- Prediction label and textbox
  68. local predictionLabel = Instance.new("TextLabel")
  69. predictionLabel.Size = UDim2.new(0, 100, 0, 30)
  70. predictionLabel.Position = UDim2.new(0, 10, 0, 40)
  71. predictionLabel.Text = "Prediction:"
  72. predictionLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  73. predictionLabel.Parent = settingsFrame
  74.  
  75. local predictionBox = Instance.new("TextBox")
  76. predictionBox.Size = UDim2.new(0, 80, 0, 30)
  77. predictionBox.Position = UDim2.new(0, 110, 0, 40)
  78. predictionBox.Text = tostring(predictionValue)
  79. predictionBox.Parent = settingsFrame
  80.  
  81. -- Function to find the closest player to the middle of the screen
  82. local function getClosestPlayerToCenter()
  83. local closestPlayer = nil
  84. local shortestDistance = math.huge -- Start with a very large distance
  85.  
  86. -- Find the center of the screen (middle point)
  87. local screenCenter = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
  88.  
  89. for _, p in pairs(game.Players:GetPlayers()) do
  90. if p ~= player then
  91. local character = p.Character
  92. if character and character:FindFirstChild("Head") then
  93. local head = character.Head
  94. local headPos = camera:WorldToScreenPoint(head.Position)
  95.  
  96. -- Calculate the distance from the screen center to the player's head
  97. local distance = (screenCenter - Vector2.new(headPos.X, headPos.Y)).Magnitude
  98.  
  99. -- Keep track of the closest player to the center of the screen
  100. if distance < shortestDistance then
  101. shortestDistance = distance
  102. closestPlayer = p
  103. end
  104. end
  105. end
  106. end
  107. return closestPlayer
  108. end
  109.  
  110. -- Function to smoothly drag the camera towards the locked player (with prediction)
  111. local function smoothlyDragToPlayer(targetPlayer)
  112. if targetPlayer and targetPlayer.Character then
  113. local character = targetPlayer.Character
  114. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  115.  
  116. if humanoidRootPart then
  117. -- Get the player's current velocity
  118. local humanoid = character:FindFirstChild("Humanoid")
  119. local velocity = humanoidRootPart.Velocity
  120. local predictedPosition = humanoidRootPart.Position + velocity * predictionValue -- Use the dynamic prediction value
  121.  
  122. -- Interpolate between the current camera position and the predicted position
  123. local currentPosition = camera.CFrame.Position
  124. local newCameraPosition = currentPosition:Lerp(predictedPosition, smoothSpeed)
  125.  
  126. -- Smoothly update the camera position
  127. camera.CFrame = CFrame.new(newCameraPosition, predictedPosition)
  128. end
  129. end
  130. end
  131.  
  132. -- Function to lock onto the nearest player
  133. local function lockOn()
  134. local targetPlayer = getClosestPlayerToCenter()
  135. if targetPlayer then
  136. lockedPlayer = targetPlayer
  137. isLockedOn = true
  138. lockButton.Text = "Lock On (Active)"
  139. cameraShake()
  140.  
  141. -- Listen for when the locked player's humanoid dies or becomes ragdolled
  142. local function onHumanoidDied()
  143. stopLockingOn() -- Stop locking on if the player dies or ragdolls
  144. end
  145.  
  146. local function onHumanoidHealthChanged()
  147. -- Check if the humanoid health is less than or equal to 0 (player is knocked out or ragdolled)
  148. if lockedPlayer and lockedPlayer.Character then
  149. local humanoid = lockedPlayer.Character:FindFirstChildOfClass("Humanoid")
  150. if humanoid and humanoid.Health <= 0 then
  151. stopLockingOn() -- Stop lock-on if the player is knocked out
  152. end
  153. end
  154. end
  155.  
  156. -- Add events to listen for death or ragdolling
  157. if lockedPlayer and lockedPlayer.Character then
  158. local humanoid = lockedPlayer.Character:FindFirstChildOfClass("Humanoid")
  159. if humanoid then
  160. humanoid.Died:Connect(onHumanoidDied) -- Listen for death
  161. humanoid.HealthChanged:Connect(onHumanoidHealthChanged) -- Listen for health changes
  162. end
  163. end
  164. else
  165. print("No player found to lock onto")
  166. end
  167. end
  168.  
  169. -- Function to stop locking on
  170. local function stopLockingOn()
  171. lockedPlayer = nil
  172. isLockedOn = false
  173. lockButton.Text = "Lock On"
  174. end
  175.  
  176. -- Camera shake effect
  177. local function cameraShake()
  178. local originalPosition = camera.CFrame.Position
  179. for i = 1, 10 do
  180. camera.CFrame = CFrame.new(originalPosition + Vector3.new(math.random(), math.random(), math.random()) * 0.1)
  181. wait(0.05)
  182. end
  183. camera.CFrame = CFrame.new(originalPosition)
  184. end
  185.  
  186. -- Connect the button click event to toggle lock-on
  187. lockButton.MouseButton1Click:Connect(function()
  188. if isLockedOn then
  189. stopLockingOn() -- Stop lock-on if already active
  190. else
  191. lockOn() -- Lock onto the closest player to the middle of the screen
  192. end
  193. end)
  194.  
  195. -- Show/hide the settings tab when the settings button is clicked
  196. settingsButton.MouseButton1Click:Connect(function()
  197. settingsFrame.Visible = not settingsFrame.Visible -- Toggle visibility
  198. end)
  199.  
  200. -- Update to continuously drag the camera towards the locked player's predicted position
  201. game:GetService("RunService").Heartbeat:Connect(function()
  202. if isLockedOn and lockedPlayer then
  203. smoothlyDragToPlayer(lockedPlayer) -- Smooth
Advertisement
Add Comment
Please, Sign In to add comment