Anukun_Lucifer

SwordComboClient

Aug 16th, 2025
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | Gaming | 0 0
  1. local tool = script.Parent
  2. local player = game.Players.LocalPlayer
  3. local humanoid = nil
  4. local combo = 1
  5. local maxCombo = 4
  6. local debounce = false
  7.  
  8. -- Reference the Animation objects inside the Tool
  9. local animations = {}
  10. for i = 1, maxCombo do
  11.     local anim = tool:FindFirstChild("Slash"..i)
  12.     if anim and anim:IsA("Animation") then
  13.         animations[i] = anim
  14.     end
  15. end
  16.  
  17. local function playSlashSound()
  18.     local sound = tool.Handle:FindFirstChild("SlashSound")
  19.     if sound then
  20.         sound:Play()
  21.     end
  22. end
  23.  
  24. local function onActivated()
  25.     if debounce then return end
  26.     debounce = true
  27.  
  28.     if not humanoid then
  29.         local character = player.Character or player.CharacterAdded:Wait()
  30.         humanoid = character:FindFirstChildOfClass("Humanoid")
  31.     end
  32.  
  33.     -- ลด WalkSpeed ลงครึ่งหนึ่งขณะโจมตี
  34.     local originalWalkSpeed = humanoid and humanoid.WalkSpeed or 16
  35.  
  36.     -- ลด JumpPower หรือ JumpHeight ลงครึ่งหนึ่งขณะโจมตี
  37.     local useJumpPower = humanoid and humanoid.UseJumpPower ~= nil and humanoid.UseJumpPower or false
  38.     local originalJumpValue = 0
  39.     if humanoid then
  40.         humanoid.WalkSpeed = originalWalkSpeed / 2
  41.         if useJumpPower then
  42.             originalJumpValue = humanoid.JumpPower
  43.             humanoid.JumpPower = originalJumpValue / 2
  44.         else
  45.             originalJumpValue = humanoid.JumpHeight
  46.             humanoid.JumpHeight = originalJumpValue / 2
  47.         end
  48.     end
  49.  
  50.     -- Play combo animation
  51.     local animObj = animations[combo]
  52.     local animTrack = nil
  53.     if animObj and humanoid then
  54.         animTrack = humanoid:LoadAnimation(animObj)
  55.         animTrack:Play()
  56.     end
  57.     playSlashSound()
  58.  
  59.     -- Set up hit detection for this swing (damage only once per activation)
  60.     local hitRegistered = false
  61.     local connection
  62.     connection = tool.Handle.Touched:Connect(function(hit)
  63.         if hitRegistered then return end
  64.         local enemyHumanoid = nil
  65.         local enemyModel = nil
  66.         if hit and hit.Parent and hit.Parent ~= player.Character then
  67.             enemyHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
  68.             enemyModel = hit.Parent
  69.         end
  70.         if enemyHumanoid and enemyModel then
  71.             -- Fire server to apply damage and effects
  72.             local damageValue = tool:FindFirstChild("Damage")
  73.             local damage = damageValue and damageValue.Value
  74.             game.ReplicatedStorage.SwordHitEvent:FireServer(enemyModel, damage, hit.Position)
  75.             hitRegistered = true
  76.             connection:Disconnect()
  77.         end
  78.     end)
  79.  
  80.     combo = combo + 1
  81.     if combo > maxCombo then
  82.         combo = 1
  83.     end
  84.  
  85.     -- Wait for animation to finish before allowing next attack
  86.     if animTrack then
  87.         local finished = false
  88.         animTrack.Stopped:Connect(function()
  89.             finished = true
  90.         end)
  91.         while not finished do
  92.             task.wait()
  93.         end
  94.     else
  95.         task.wait(0.4) -- fallback if animation missing
  96.     end
  97.  
  98.     -- Disconnect touch connection if still active (safety)
  99.     if connection and connection.Connected then
  100.         connection:Disconnect()
  101.     end
  102.  
  103.     -- คืนค่า WalkSpeed เดิมหลังจบการโจมตี
  104.     if humanoid then
  105.         humanoid.WalkSpeed = originalWalkSpeed
  106.         if useJumpPower then
  107.             humanoid.JumpPower = originalJumpValue
  108.         else
  109.             humanoid.JumpHeight = originalJumpValue
  110.         end
  111.     end
  112.  
  113.     debounce = false
  114. end
  115.  
  116. tool.Activated:Connect(onActivated)
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment