Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Debris = game:GetService("Debris")
- local localPlayer = Players.LocalPlayer
- local camera = workspace.CurrentCamera
- local isAiming = false
- local targetPlayer = nil
- local highlight = nil
- local canDash = true
- local dashCooldown = 1.5 -- Cooldown time in seconds
- local dashForce = 100 -- Adjust the dash force as needed
- -- Function to find the nearest player to the local player
- local function getNearestPlayer()
- local closestDistance = math.huge
- local closestPlayer = nil
- local localCharacter = localPlayer.Character
- if not localCharacter or not localCharacter:FindFirstChild("HumanoidRootPart") then return nil end
- local localPosition = localCharacter.HumanoidRootPart.Position
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= localPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Head") then
- local distance = (player.Character.HumanoidRootPart.Position - localPosition).Magnitude
- if distance < closestDistance then
- closestDistance = distance
- closestPlayer = player
- end
- end
- end
- return closestPlayer
- end
- -- Function to start aiming at the target player's head
- local function startAiming()
- targetPlayer = getNearestPlayer()
- if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then
- isAiming = true
- -- Create and configure the highlight
- highlight = Instance.new("Highlight")
- highlight.Name = "TargetHighlight"
- highlight.FillColor = Color3.fromRGB(255, 0, 0) -- Red fill
- highlight.OutlineColor = Color3.fromRGB(255, 255, 255) -- White outline
- highlight.FillTransparency = 0.5
- highlight.OutlineTransparency = 0
- highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
- highlight.Adornee = targetPlayer.Character
- highlight.Parent = targetPlayer.Character
- -- Optional: Lock mouse to center
- UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
- end
- end
- -- Function to stop aiming
- local function stopAiming()
- isAiming = false
- targetPlayer = nil
- -- Remove the highlight if it exists
- if highlight then
- highlight:Destroy()
- highlight = nil
- end
- -- Optional: Release mouse lock
- UserInputService.MouseBehavior = Enum.MouseBehavior.Default
- end
- -- Function to perform the dash
- local function dash()
- if not canDash then return end
- canDash = false
- local character = localPlayer.Character
- if character and character:FindFirstChild("HumanoidRootPart") and character:FindFirstChild("Humanoid") then
- local hrp = character.HumanoidRootPart
- local humanoid = character.Humanoid
- -- Determine dash direction
- local moveDirection = humanoid.MoveDirection
- if moveDirection.Magnitude == 0 then
- -- If no movement input, dash forward relative to camera
- moveDirection = camera.CFrame.LookVector
- end
- -- Create BodyVelocity to apply dash force
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.Velocity = moveDirection.Unit * dashForce
- bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
- bodyVelocity.P = 1250
- bodyVelocity.Parent = hrp
- -- Remove BodyVelocity after a short duration
- Debris:AddItem(bodyVelocity, 0.2)
- end
- -- Cooldown before next dash
- task.delay(dashCooldown, function()
- canDash = true
- end)
- end
- -- Listen for key press
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.KeyCode == Enum.KeyCode.E then
- if isAiming then
- stopAiming()
- else
- startAiming()
- end
- elseif input.KeyCode == Enum.KeyCode.Q then
- dash()
- end
- end)
- -- Update camera every frame to look at the target
- RunService.RenderStepped:Connect(function()
- if isAiming and targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then
- local headPosition = targetPlayer.Character.Head.Position
- local cameraPosition = camera.CFrame.Position
- camera.CFrame = CFrame.new(cameraPosition, headPosition)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement