Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------
- -------------------- Variables
- local players = game.Players
- local player = players.LocalPlayer
- local tool = script.Parent.Parent
- local character = player.Character or player.CharacterAdded:Wait()
- local human = character:WaitForChild("Humanoid")
- local mouse = player:GetMouse()
- local remoteEvent = tool:WaitForChild("remote_event")
- local blocking = false
- local equipped = false
- local attacking = false
- local CurrentAttackAnimation = 0
- local HitCoolDown = false
- --------------------
- -------------------- Load Animations
- function loadAnims()
- local success, result = pcall(function()
- wait(.5)
- anim_idle = human:LoadAnimation(tool.Animations.idle)
- anim_idle.Looped = true
- anim_attack_1 = human:LoadAnimation(tool.Animations.attack_1)
- anim_attack_1.Looped = false
- anim_attack_2 = human:LoadAnimation(tool.Animations.attack_2)
- anim_attack_2.Looped = false
- anim_block_1 = human:LoadAnimation(tool.Animations.block_1)
- anim_block_1.Looped = true
- anim_block_2 = human:LoadAnimation(tool.Animations.block_2)
- anim_block_2.Looped = true
- end)
- if success == false then
- character = player.Character or player.CharacterAdded:Wait()
- human = character:WaitForChild("Humanoid")
- loadAnims()
- end
- end
- loadAnims()
- --------------------
- -------------------- Arrays
- local attack_Animations = {anim_attack_1, anim_attack_2}
- local block_Animations = {anim_block_1, anim_block_2}
- --------------------
- -------------------- Functions
- function PlayAnimation(animation, Time) --Remove any client-side looped animation glitches
- animation:Play()
- wait(Time)
- animation:Stop()
- end
- function PickAttackAnimation() --Cycle through attack animations
- CurrentAttackAnimation = CurrentAttackAnimation + 1
- if CurrentAttackAnimation > #attack_Animations then
- CurrentAttackAnimation = 1
- end
- return attack_Animations[CurrentAttackAnimation]
- end
- --------------------
- -------------------- Weapon Actions
- tool.Equipped:Connect(function()
- equipped = true
- anim_idle:Play()
- end)
- tool.Unequipped:Connect(function()
- remoteEvent:FireServer("Block", false)
- blocking = false
- equipped = false
- anim_idle:Stop()
- end)
- tool.Activated:Connect(function()
- if equipped == true and blocking == false and attacking == false then
- remoteEvent:FireServer("Block", false)
- attacking = true
- PlayAnimation(PickAttackAnimation(), 1.25)
- attacking = false
- end
- end)
- mouse.Button2Down:Connect(function()
- if attacking == false and equipped == true then
- blocking = true
- remoteEvent:FireServer("Block", true)
- spawn(function()
- remoteEvent:FireServer("Stun", true)
- wait(2)
- remoteEvent:FireServer("Stun", false)
- end)
- CurrentBlockAnimation = block_Animations[math.random(1, #block_Animations)]
- CurrentBlockAnimation:Play()
- end
- end)
- mouse.Button2Up:Connect(function()
- blocking = false
- remoteEvent:FireServer("Block", false)
- CurrentBlockAnimation:Stop()
- end)
- tool.blade.Touched:Connect(function(hit)
- local humanoid = hit.Parent:FindFirstChild("Humanoid")
- if humanoid and HitCoolDown == false and attacking == true then
- HitCoolDown = true
- remoteEvent:FireServer("Attack", humanoid)
- wait(.5)
- HitCoolDown = false
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement