Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Tool = script.Parent
- local Handle = Tool:WaitForChild("Handle")
- local Players = game:GetService("Players")
- local Debris = game:GetService("Debris")
- local RunService = game:GetService("RunService")
- local Damage = 10
- local AttackCooldown = 0.5
- local MaxCombo = 4
- local ComboCooldown = 1
- local Player
- local Character
- local Humanoid
- local Torso
- local ToolEquipped = false
- local LastAttackTime = 0
- local AttackCount = 0
- local Sounds = {
- Slash = Handle:WaitForChild("SwordSlash"),
- Lunge = Handle:WaitForChild("SwordLunge"),
- Unsheath = Handle:WaitForChild("Unsheath")
- }
- function CheckIfAlive()
- return Player and Character and Humanoid and Torso and Humanoid.Health > 0
- end
- function TagHumanoid(humanoid)
- local tag = Instance.new("ObjectValue")
- tag.Name = "creator"
- tag.Value = Player
- Debris:AddItem(tag, 2)
- tag.Parent = humanoid
- end
- function Blow(hit)
- if not hit or not hit.Parent or not CheckIfAlive() or not ToolEquipped then return end
- local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
- if humanoid and humanoid.Health > 0 and hit.Parent ~= Character then
- TagHumanoid(humanoid)
- humanoid:TakeDamage(Damage)
- end
- end
- local Connection = Handle.Touched:Connect(Blow)
- function PlayAttackAnimation()
- local animName = "Attack" .. tostring(math.clamp(AttackCount, 1, MaxCombo))
- local anim = Handle:FindFirstChild(animName)
- if anim and Humanoid then
- local track = Humanoid:LoadAnimation(anim)
- track:Play()
- end
- end
- function Activated()
- if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then return end
- local currentTime = tick()
- local cooldown = AttackCooldown
- if AttackCount >= MaxCombo then
- cooldown = ComboCooldown
- end
- if currentTime - LastAttackTime < cooldown then return end
- LastAttackTime = currentTime
- AttackCount = AttackCount + 1
- if AttackCount > MaxCombo then
- AttackCount = 1
- end
- Damage = 10
- Sounds.Slash:Play()
- PlayAttackAnimation()
- end
- function Equipped()
- Character = Tool.Parent
- Player = Players:GetPlayerFromCharacter(Character)
- Humanoid = Character:FindFirstChildOfClass("Humanoid")
- Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
- if not CheckIfAlive() then return end
- ToolEquipped = true
- Sounds.Unsheath:Play()
- end
- function Unequipped()
- ToolEquipped = false
- AttackCount = 0
- end
- Tool.Activated:Connect(Activated)
- Tool.Equipped:Connect(Equipped)
- Tool.Unequipped:Connect(Unequipped)
Advertisement
Add Comment
Please, Sign In to add comment