Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local Debris = game:GetService("Debris")
- local Players = game:GetService("Players")
- local Tool = script.Parent
- local Sword = Tool.Handle
- local antiTK = true
- local idleDamage = 5
- local slashDamage = 10
- local lungeDamage = 35
- local damage = idleDamage
- local SlashSound = Sword:WaitForChild("SlashSound")
- local LungeSound = Sword:WaitForChild("LungeSound")
- local UnsheathSound = Sword:WaitForChild("UnsheathSound")
- local humanoidParts = {
- ["Head"] = true,
- ["Left Arm"] = true,
- ["Left Leg"] = true,
- ["Right Arm"] = true,
- ["Right Leg"] = true,
- ["Torso"] = true,
- }
- function swordUp()
- Tool.GripForward, Tool.GripRight, Tool.GripUp = Vector3.new(-1, 0, -0), Vector3.new(0, 0, -1), Vector3.new(0, 1, -0)
- end
- function swordOut()
- Tool.GripForward, Tool.GripRight, Tool.GripUp = Vector3.new(0, 1, -0), Vector3.new(0, -0, -1), Vector3.new(1, -0, -0)
- end
- function toolAnimation(name)
- local anim = Instance.new("StringValue", Tool)
- anim.Name = "toolanim"
- anim.Value = name
- end
- function slash()
- damage = slashDamage
- SlashSound:play()
- toolAnimation("Slash")
- end
- function lunge()
- damage = lungeDamage
- LungeSound:play()
- toolAnimation("Lunge")
- wait(.25)
- swordOut()
- wait(.75)
- swordUp()
- end
- Tool.Enabled = true
- local lastSwing = 0
- Tool.Activated:connect(function()
- if not Tool.Enabled then return end
- Tool.Enabled = false
- local cooldown = RunService.Stepped:wait()
- if (cooldown - lastSwing < .2) then
- lunge()
- else
- slash()
- end
- lastSwing = cooldown
- damage = idleDamage
- Tool.Enabled = true
- end)
- function isHumanoidPart(partThatWasHitWithSword)
- return partThatWasHitWithSword.Parent and humanoidParts[partThatWasHitWithSword.Name]
- end
- function canDamage(attackingPlayer, defendingPlayer)
- return not antiTK or attackingPlayer.TeamColor ~= defendingPlayer.TeamColor
- end
- function swordIsInHand(attackingCharacter)
- local rightArm = attackingCharacter:FindFirstChild("Right Arm")
- local rightGripJoint = rightArm and rightArm:FindFirstChild("RightGrip")
- return rightGripJoint and (rightGripJoint.Part0 == Sword or rightGripJoint.Part1 == Sword)
- end
- function tagHumanoid(humanoid, player)
- local creatorTag = Instance.new("ObjectValue", humanoid)
- creatorTag.Value = player
- creatorTag.Name = "creator"
- Debris:AddItem(creatorTag, 1)
- end
- Sword.Touched:Connect(function(hit)
- if not isHumanoidPart(hit) then return end
- local attackingCharacter = Tool.Parent
- local attackingPlayer = Players:playerFromCharacter(attackingCharacter)
- local attackingHumanoid = attackingCharacter:FindFirstChild("Humanoid")
- local potentialDefendingCharacter = hit.Parent
- local defendingHumanoid = potentialDefendingCharacter:FindFirstChild("Humanoid")
- local defendingPlayer = Players:GetPlayerFromCharacter(potentialDefendingCharacter)
- if defendingHumanoid and attackingHumanoid and defendingHumanoid ~= attackingHumanoid then
- -- Allow damage of NPCs
- if not defendingPlayer or canDamage(attackingPlayer, defendingPlayer) then
- tagHumanoid(defendingHumanoid, attackingPlayer)
- defendingHumanoid:TakeDamage(damage)
- end
- end
- end)
- Tool.Equipped:Connect(function() UnsheathSound:play() end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement