Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables for the sword and booleans
- local sword = script.Parent
- local canAttack = true
- local canDamage = false
- -- Function that runs when any part touches the blade
- function onTouch(part)
- local character = part.Parent
- local player = game.Players:GetPlayerFromCharacter(character)
- -- Check if player exists and can damage is true, then deal the damage
- if player then
- if canDamage == true then
- character.Humanoid:TakeDamage(20)
- end
- end
- end
- sword.Blade.Touched:Connect(onTouch)
- -- Attack function that swings sword and activates damage
- function Attack()
- -- Sword swing animation that is located in the player that holds the sword
- local attackAnim = sword.Parent.Humanoid:LoadAnimation(script.SwordSwing)
- -- If statement that attacks only when canAttack is true
- if canAttack == true then
- -- Play attack animation and set canAttack to false
- attackAnim:Play()
- canAttack = false
- -- Sword damageable for 0.5s
- canDamage = true
- wait(0.5)
- -- Deactivate sword damage for 0.25s before being able to do damage again
- canDamage = false
- wait(0.25)
- canAttack = true
- end
- end
- sword.Activated:Connect(Attack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement