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 Player
- local Character
- local Humanoid
- local Torso
- local ToolEquipped = false
- local Damage = 10
- local AttackCount = 1
- local LastAttackTime = 0
- local ComboCooldown = 1
- local AttackCooldown = 0.5
- local Hit1Anim
- local Hit2Anim
- local Hit3Anim
- local Hit4Anim
- local Slash1 = Handle:WaitForChild("Slash1")
- local Slash2 = Handle:WaitForChild("Slash2")
- local Slash3 = Handle:WaitForChild("Slash3")
- local Slash4 = Handle:WaitForChild("Slash4")
- local 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 LoadAnimations()
- if Humanoid then
- local anim1 = Handle:FindFirstChild("hit1")
- local anim2 = Handle:FindFirstChild("hit2")
- local anim3 = Handle:FindFirstChild("hit3")
- local anim4 = Handle:FindFirstChild("hit4")
- if anim1 then Hit1Anim = Humanoid:LoadAnimation(anim1) end
- if anim2 then Hit2Anim = Humanoid:LoadAnimation(anim2) end
- if anim3 then Hit3Anim = Humanoid:LoadAnimation(anim3) end
- if anim4 then Hit4Anim = Humanoid:LoadAnimation(anim4) end
- end
- end
- function PlayAttackAnimationAndSound()
- if AttackCount == 1 then
- if Hit1Anim then Hit1Anim:Stop(); Hit1Anim:Play() end
- Slash1:Play()
- elseif AttackCount == 2 then
- if Hit2Anim then Hit2Anim:Stop(); Hit2Anim:Play() end
- Slash2:Play()
- elseif AttackCount == 3 then
- if Hit3Anim then Hit3Anim:Stop(); Hit3Anim:Play() end
- Slash3:Play()
- elseif AttackCount == 4 then
- if Hit4Anim then Hit4Anim:Stop(); Hit4Anim:Play() end
- Slash4:Play()
- end
- end
- function Activated()
- if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then return end
- local currentTime = tick()
- local requiredCooldown = (AttackCount > 4) and ComboCooldown or AttackCooldown
- if currentTime - LastAttackTime < requiredCooldown then
- return
- end
- LastAttackTime = currentTime
- if AttackCount > 4 then
- AttackCount = 1
- end
- PlayAttackAnimationAndSound()
- AttackCount = AttackCount + 1
- 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
- LoadAnimations()
- Unsheath:Play()
- end
- function Unequipped()
- ToolEquipped = false
- AttackCount = 1
- end
- Tool.Activated:Connect(Activated)
- Tool.Equipped:Connect(Equipped)
- Tool.Unequipped:Connect(Unequipped)
Advertisement
Add Comment
Please, Sign In to add comment