Facebook
From Josh, 2 Months ago, written in Lua.
Embed
Download Paste or View Raw
Hits: 190
  1. -- Create the Tool instance
  2. local tool = Instance.new("Tool")
  3.  
  4. -- Set the tool's properties
  5. tool.Name = "Swift Sweep"
  6. tool.RequiresHandle = false  -- Set to true if you have a handle part
  7. tool.CanBeDropped = true     -- Change as needed
  8.  
  9. -- Add a description or other properties
  10. tool.ToolTip = "A swift sweeping tool for fast clean-ups."
  11.  
  12. -- Animation IDs
  13. local animationId = "rbxassetid://16944345619"
  14. local pushBackAnimationId = "rbxassetid://10471478869"  -- Push-back animation ID (replace with your animation ID if different)
  15. -- Trail texture ID
  16. local trailTextureId = "rbxassetid://3840203982"
  17.  
  18. -- Damage parameters
  19. local minDamage = 10
  20. local maxDamage = 14
  21. local pushBackDistance = 15  -- Distance to push back the player
  22.  
  23. -- Function to play the animation
  24. local function playAnimation()
  25.     local player = game.Players.LocalPlayer
  26.     local character = player.Character or player.CharacterAdded:Wait()
  27.     local humanoid = character:WaitForChild("Humanoid")
  28.  
  29.     -- Load the animation
  30.     local animation = Instance.new("Animation")
  31.     animation.AnimationId = animationId
  32.     local animationTrack = humanoid:LoadAnimation(animation)
  33.  
  34.     -- Play the animation
  35.     animationTrack:Play()
  36. end
  37.  
  38. -- Function to create a trail on the left leg
  39. local function createTrail()
  40.     local player = game.Players.LocalPlayer
  41.     local character = player.Character or player.CharacterAdded:Wait()
  42.     local leftLeg = character:FindFirstChild("Left Leg") or character:FindFirstChild("LeftUpperLeg")
  43.  
  44.     if leftLeg then
  45.         -- Create attachments for the trail
  46.         local attachment0 = Instance.new("Attachment", leftLeg)
  47.         local attachment1 = Instance.new("Attachment", leftLeg)
  48.         attachment1.Position = Vector3.new(0, -2, 0)  -- Adjust the position as needed
  49.  
  50.         -- Create the trail
  51.         local trail = Instance.new("Trail")
  52.         trail.Attachment0 = attachment0
  53.         trail.Attachment1 = attachment1
  54.         trail.Texture = trailTextureId
  55.         trail.Lifetime = 0.9
  56.  
  57.         -- Set the transparency to fade out
  58.         trail.Transparency = NumberSequence.new({
  59.             NumberSequenceKeypoint.new(0, 0),    -- Fully visible at the start
  60.             NumberSequenceKeypoint.new(1, 1)     -- Fully transparent at the end
  61.         })
  62.  
  63.         trail.Parent = leftLeg
  64.  
  65.         -- Optional: Remove the trail after it has completely faded out
  66.         game:GetService("Debris"):AddItem(trail, 1.0)  -- Slightly longer than lifetime to ensure complete removal
  67.     end
  68. end
  69.  
  70. -- Function to push back the player in front and deal damage after a delay
  71. local function pushBackAndDamage()
  72.     local player = game.Players.LocalPlayer
  73.     local character = player.Character or player.CharacterAdded:Wait()
  74.     local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  75.     local lookDirection = humanoidRootPart.CFrame.LookVector
  76.  
  77.     -- Perform a raycast in front of the player
  78.     local raycastParams = RaycastParams.new()
  79.     raycastParams.FilterDescendantsInstances = {character}
  80.     raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
  81.  
  82.     local raycastResult = workspace:Raycast(humanoidRootPart.Position, lookDirection * 20, raycastParams)  -- Increased raycast distance to 20 studs
  83.    
  84.     if raycastResult and raycastResult.Instance and raycastResult.Instance.Parent:FindFirstChild("Humanoid") then
  85.         local hitCharacter = raycastResult.Instance.Parent
  86.         local hitHumanoidRootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
  87.         local hitHumanoid = hitCharacter:FindFirstChild("Humanoid")
  88.        
  89.         if hitHumanoidRootPart and hitHumanoid then
  90.             -- Delay before applying damage, push-back, and playing the push-back animation
  91.             wait(0.4)
  92.  
  93.             -- Calculate damage within the specified range
  94.             local damage = math.random(minDamage, maxDamage)
  95.  
  96.             -- Apply damage to the hit player
  97.             hitHumanoid:TakeDamage(damage)
  98.  
  99.             -- Calculate push-back direction and force
  100.             local pushBackDirection = (hitHumanoidRootPart.Position - humanoidRootPart.Position).unit
  101.             local pushBackForce = pushBackDirection * pushBackDistance
  102.  
  103.             -- Apply push-back force to the hit player
  104.             hitHumanoidRootPart.Velocity = pushBackForce
  105.  
  106.             -- Load and play the push-back animation on the hit player
  107.             local pushBackAnimation = Instance.new("Animation")
  108.             pushBackAnimation.AnimationId = pushBackAnimationId
  109.             local pushBackAnimationTrack = hitHumanoid:LoadAnimation(pushBackAnimation)
  110.             pushBackAnimationTrack:Play()
  111.  
  112.             print("Dealt " .. damage .. " damage, pushed back player, and played push-back animation on player: " .. hitCharacter.Name)
  113.         end
  114.     else
  115.         print("No player found in front.")
  116.     end
  117. end
  118.  
  119. -- Add functionality to the tool
  120. tool.Activated:Connect(function()
  121.     playAnimation()
  122.     createTrail()
  123.     pushBackAndDamage()
  124. end)
  125.  
  126. -- Add the tool to the player's backpack
  127. tool.Parent = game.Players.LocalPlayer.Backpack
  128.