Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent
- local player = game.Players.LocalPlayer
- local humanoid = nil
- local combo = 1
- local maxCombo = 4
- local debounce = false
- -- Reference the Animation objects inside the Tool
- local animations = {}
- for i = 1, maxCombo do
- local anim = tool:FindFirstChild("Slash"..i)
- if anim and anim:IsA("Animation") then
- animations[i] = anim
- end
- end
- local function playSlashSound()
- local sound = tool.Handle:FindFirstChild("SlashSound")
- if sound then
- sound:Play()
- end
- end
- local function onActivated()
- if debounce then return end
- debounce = true
- if not humanoid then
- local character = player.Character or player.CharacterAdded:Wait()
- humanoid = character:FindFirstChildOfClass("Humanoid")
- end
- -- ลด WalkSpeed ลงครึ่งหนึ่งขณะโจมตี
- local originalWalkSpeed = humanoid and humanoid.WalkSpeed or 16
- -- ลด JumpPower หรือ JumpHeight ลงครึ่งหนึ่งขณะโจมตี
- local useJumpPower = humanoid and humanoid.UseJumpPower ~= nil and humanoid.UseJumpPower or false
- local originalJumpValue = 0
- if humanoid then
- humanoid.WalkSpeed = originalWalkSpeed / 2
- if useJumpPower then
- originalJumpValue = humanoid.JumpPower
- humanoid.JumpPower = originalJumpValue / 2
- else
- originalJumpValue = humanoid.JumpHeight
- humanoid.JumpHeight = originalJumpValue / 2
- end
- end
- -- Play combo animation
- local animObj = animations[combo]
- local animTrack = nil
- if animObj and humanoid then
- animTrack = humanoid:LoadAnimation(animObj)
- animTrack:Play()
- end
- playSlashSound()
- -- Set up hit detection for this swing (damage only once per activation)
- local hitRegistered = false
- local connection
- connection = tool.Handle.Touched:Connect(function(hit)
- if hitRegistered then return end
- local enemyHumanoid = nil
- local enemyModel = nil
- if hit and hit.Parent and hit.Parent ~= player.Character then
- enemyHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
- enemyModel = hit.Parent
- end
- if enemyHumanoid and enemyModel then
- -- Fire server to apply damage and effects
- local damageValue = tool:FindFirstChild("Damage")
- local damage = damageValue and damageValue.Value
- game.ReplicatedStorage.SwordHitEvent:FireServer(enemyModel, damage, hit.Position)
- hitRegistered = true
- connection:Disconnect()
- end
- end)
- combo = combo + 1
- if combo > maxCombo then
- combo = 1
- end
- -- Wait for animation to finish before allowing next attack
- if animTrack then
- local finished = false
- animTrack.Stopped:Connect(function()
- finished = true
- end)
- while not finished do
- task.wait()
- end
- else
- task.wait(0.4) -- fallback if animation missing
- end
- -- Disconnect touch connection if still active (safety)
- if connection and connection.Connected then
- connection:Disconnect()
- end
- -- คืนค่า WalkSpeed เดิมหลังจบการโจมตี
- if humanoid then
- humanoid.WalkSpeed = originalWalkSpeed
- if useJumpPower then
- humanoid.JumpPower = originalJumpValue
- else
- humanoid.JumpHeight = originalJumpValue
- end
- end
- debounce = false
- end
- tool.Activated:Connect(onActivated)
Advertisement
Add Comment
Please, Sign In to add comment