Advertisement
XXsuperninjaXXop

Untitled

Jun 8th, 2025
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.80 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local player = Players.LocalPlayer
  5. local char = player.Character or player.CharacterAdded:Wait()
  6. local humanoid = char:WaitForChild("Humanoid")
  7. local rootPart = char:WaitForChild("HumanoidRootPart")
  8.  
  9. local keybind = require(game.ReplicatedStorage.CoolModules.Keybind)
  10.  
  11. local dirteffect = char["Left Leg"].LeftFootAttachment:WaitForChild("DirtEffect")
  12.  
  13. local FrontDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Forward)
  14. local LeftDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Left)
  15. local RightDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Right)
  16. local BackDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Back)
  17.  
  18. local dashConfig = {
  19.     speed = 90,
  20.     cdtime = 2.5,
  21.     duration = 0.3,
  22.     maxforce = Vector3.new(1, 0, 1) * 300000,
  23.     minvelocity = 0.2
  24. }
  25.  
  26. local dashState = {
  27.     canDash = true,
  28.     isDashing = false,
  29.     dashStartTime = 0
  30. }
  31.  
  32. local action = keybind.GetAction("Fight", "Dash")
  33. action.KeyboardBinding.KeyCode = Enum.KeyCode.Q
  34. action.GamepadBinding.KeyCode = Enum.KeyCode.ButtonX
  35. action.KeyboardBinding.UIButton = player.PlayerGui.MobileButtons.Frame.DashButton
  36. keybind.EnableContext("Fight")
  37.  
  38. local dashCDIcon = player.PlayerGui.Cooldowns.Frame.Dash
  39.  
  40. local function getDashDirection()
  41.     local moveDirection = humanoid.MoveDirection
  42.     if moveDirection.Magnitude == 0 then
  43.         moveDirection = rootPart.CFrame.LookVector
  44.     end
  45.  
  46.     local relativeDirection = rootPart.CFrame:VectorToObjectSpace(moveDirection)
  47.  
  48.     local forwardDot = relativeDirection.Z
  49.     local rightDot = relativeDirection.X
  50.  
  51.     local threshold = 0.5
  52.  
  53.     if forwardDot > threshold then
  54.         return BackDash
  55.     elseif forwardDot < -threshold then
  56.         return FrontDash
  57.     elseif rightDot > threshold then
  58.         return RightDash
  59.     elseif rightDot < -threshold then
  60.         return LeftDash
  61.     else
  62.         return FrontDash
  63.     end
  64. end
  65.  
  66. local function Dash()
  67.     if not dashState.canDash then return end
  68.     script.SFX.dash:Play()
  69.     dashCDIcon.BackgroundTransparency = 0.7
  70.     dashCDIcon.ImageTransparency = 0.7
  71.     dashCDIcon.UIStroke.Transparency = 0.7
  72.     if humanoid.FloorMaterial ~= Enum.Material.Air then
  73.         local rayOrigin = rootPart.Position
  74.         local rayDirection = Vector3.new(0, -5, 0)
  75.  
  76.         local raycastParams = RaycastParams.new()
  77.         raycastParams.FilterDescendantsInstances = {player.Character}
  78.         raycastParams.FilterType = Enum.RaycastFilterType.Exclude
  79.  
  80.         local result = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
  81.  
  82.         if result and result.Instance then
  83.             local partColor = result.Instance.Color
  84.             local grayishColor = Color3.fromHex("#a19691")
  85.  
  86.             local startColor = grayishColor:Lerp(partColor, 0.7)
  87.             local endColor = grayishColor:Lerp(partColor, 0.7)
  88.  
  89.             dirteffect.Color = ColorSequence.new{
  90.                 ColorSequenceKeypoint.new(0, startColor),
  91.                 ColorSequenceKeypoint.new(0.674, partColor),
  92.                 ColorSequenceKeypoint.new(1, endColor)
  93.             }
  94.  
  95.         end
  96.         dirteffect.Enabled = true
  97.     end
  98.    
  99.    
  100.     local currentanim :AnimationTrack
  101.     dashState.canDash = false
  102.     dashState.isDashing = true
  103.     dashState.dashStartTime = os.clock()
  104.  
  105.     currentanim = getDashDirection()
  106.    
  107.     local direction
  108.     if humanoid.MoveDirection.Magnitude > 0 then
  109.         direction = humanoid.MoveDirection.Unit
  110.     else
  111.         direction = rootPart.CFrame.LookVector
  112.     end
  113.    
  114.     local relativeDirection = char.HumanoidRootPart.CFrame:VectorToObjectSpace(char.Humanoid.MoveDirection)
  115.    
  116.    
  117.     currentanim:Play(0.05)
  118.     local bodyVelocity = Instance.new("BodyVelocity")
  119.     bodyVelocity.MaxForce = dashConfig.maxforce
  120.     bodyVelocity.Velocity = direction * dashConfig.speed * 5
  121.     bodyVelocity.Parent = rootPart
  122.    
  123.     local dashConnection
  124.     local reductionFactor = 1
  125.     dashConnection = RunService.Heartbeat:Connect(function()
  126.         local elapsed = os.clock() - dashState.dashStartTime
  127.        
  128.         if humanoid.MoveDirection.Magnitude > 0 then
  129.             direction = humanoid.MoveDirection.Unit
  130.         else
  131.             direction = rootPart.CFrame.LookVector
  132.         end
  133.         if elapsed < dashConfig.duration and
  134.             rootPart.AssemblyLinearVelocity.Magnitude > dashConfig.speed * dashConfig.minvelocity then
  135.             bodyVelocity.Velocity = direction * dashConfig.speed * reductionFactor
  136.             reductionFactor -= 0.05
  137.         else
  138.             dashState.isDashing = false
  139.             bodyVelocity:Destroy()
  140.             dashConnection:Disconnect()
  141.             task.wait(0.1)
  142.             dirteffect.Enabled = false
  143.         end
  144.     end)
  145.     task.delay(dashConfig.cdtime + dashConfig.duration, function()
  146.         dashState.canDash = true
  147.         if bodyVelocity then bodyVelocity:Destroy() end
  148.        
  149.         dashCDIcon.BackgroundTransparency = 0.4
  150.         dashCDIcon.ImageTransparency = 0.4
  151.         dashCDIcon.UIStroke.Transparency = 0.4
  152.        
  153.     end)
  154. end
  155.  
  156.  
  157. action.Pressed:Connect(function()
  158.     if dashState.canDash then
  159.         task.spawn(Dash)
  160.     end
  161. end)
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement