Advertisement
Scripith

Untitled

May 26th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local RunService = game:GetService("RunService")
  4. local Debris = game:GetService("Debris")
  5.  
  6. local localPlayer = Players.LocalPlayer
  7. local camera = workspace.CurrentCamera
  8.  
  9. local isAiming = false
  10. local targetPlayer = nil
  11. local highlight = nil
  12. local canDash = true
  13. local dashCooldown = 1.5 -- Cooldown time in seconds
  14. local dashForce = 100 -- Adjust the dash force as needed
  15.  
  16. -- Function to find the nearest player to the local player
  17. local function getNearestPlayer()
  18. local closestDistance = math.huge
  19. local closestPlayer = nil
  20. local localCharacter = localPlayer.Character
  21. if not localCharacter or not localCharacter:FindFirstChild("HumanoidRootPart") then return nil end
  22. local localPosition = localCharacter.HumanoidRootPart.Position
  23.  
  24. for _, player in pairs(Players:GetPlayers()) do
  25. if player ~= localPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Head") then
  26. local distance = (player.Character.HumanoidRootPart.Position - localPosition).Magnitude
  27. if distance < closestDistance then
  28. closestDistance = distance
  29. closestPlayer = player
  30. end
  31. end
  32. end
  33.  
  34. return closestPlayer
  35. end
  36.  
  37. -- Function to start aiming at the target player's head
  38. local function startAiming()
  39. targetPlayer = getNearestPlayer()
  40. if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then
  41. isAiming = true
  42.  
  43. -- Create and configure the highlight
  44. highlight = Instance.new("Highlight")
  45. highlight.Name = "TargetHighlight"
  46. highlight.FillColor = Color3.fromRGB(255, 0, 0) -- Red fill
  47. highlight.OutlineColor = Color3.fromRGB(255, 255, 255) -- White outline
  48. highlight.FillTransparency = 0.5
  49. highlight.OutlineTransparency = 0
  50. highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
  51. highlight.Adornee = targetPlayer.Character
  52. highlight.Parent = targetPlayer.Character
  53.  
  54. -- Optional: Lock mouse to center
  55. UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
  56. end
  57. end
  58.  
  59. -- Function to stop aiming
  60. local function stopAiming()
  61. isAiming = false
  62. targetPlayer = nil
  63.  
  64. -- Remove the highlight if it exists
  65. if highlight then
  66. highlight:Destroy()
  67. highlight = nil
  68. end
  69.  
  70. -- Optional: Release mouse lock
  71. UserInputService.MouseBehavior = Enum.MouseBehavior.Default
  72. end
  73.  
  74. -- Function to perform the dash
  75. local function dash()
  76. if not canDash then return end
  77. canDash = false
  78.  
  79. local character = localPlayer.Character
  80. if character and character:FindFirstChild("HumanoidRootPart") and character:FindFirstChild("Humanoid") then
  81. local hrp = character.HumanoidRootPart
  82. local humanoid = character.Humanoid
  83.  
  84. -- Determine dash direction
  85. local moveDirection = humanoid.MoveDirection
  86. if moveDirection.Magnitude == 0 then
  87. -- If no movement input, dash forward relative to camera
  88. moveDirection = camera.CFrame.LookVector
  89. end
  90.  
  91. -- Create BodyVelocity to apply dash force
  92. local bodyVelocity = Instance.new("BodyVelocity")
  93. bodyVelocity.Velocity = moveDirection.Unit * dashForce
  94. bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
  95. bodyVelocity.P = 1250
  96. bodyVelocity.Parent = hrp
  97.  
  98. -- Remove BodyVelocity after a short duration
  99. Debris:AddItem(bodyVelocity, 0.2)
  100. end
  101.  
  102. -- Cooldown before next dash
  103. task.delay(dashCooldown, function()
  104. canDash = true
  105. end)
  106. end
  107.  
  108. -- Listen for key press
  109. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  110. if gameProcessed then return end
  111.  
  112. if input.KeyCode == Enum.KeyCode.E then
  113. if isAiming then
  114. stopAiming()
  115. else
  116. startAiming()
  117. end
  118. elseif input.KeyCode == Enum.KeyCode.Q then
  119. dash()
  120. end
  121. end)
  122.  
  123. -- Update camera every frame to look at the target
  124. RunService.RenderStepped:Connect(function()
  125. if isAiming and targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then
  126. local headPosition = targetPlayer.Character.Head.Position
  127. local cameraPosition = camera.CFrame.Position
  128. camera.CFrame = CFrame.new(cameraPosition, headPosition)
  129. end
  130. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement