Advertisement
Guest User

Untitled

a guest
May 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local player = script.Parent.Parent.Parent;
  2. local character = player.Character;
  3. local t = character:WaitForChild("Torso");
  4.  
  5. local tool = script.Parent;
  6. local handle = tool:WaitForChild("Handle");
  7. local isBlocking = tool:WaitForChild("IsBlocking");
  8. local remoteSword = tool:WaitForChild("RemoteSword");
  9. local swinging = false;
  10. local clashId = 135436314;
  11.  
  12. local slashdmg = 40;
  13.  
  14. remoteSword.OnServerEvent:connect(function(player, event)
  15.     if event == 1 then
  16.         isBlocking.Value = true;
  17.     elseif event == 2 then
  18.         isBlocking.Value = false;
  19.     elseif event == 3 then
  20.         swinging = true;
  21.         wait(.4);
  22.         swinging = false;
  23.     end;
  24. end)
  25.  
  26. handle.Touched:connect(function(hit)
  27.     if swinging then
  28.         if hit.Parent:FindFirstChild("Humanoid") then
  29.             local h = hit.Parent:FindFirstChild("Humanoid");
  30.             for i,v in pairs(h.Parent:GetChildren()) do
  31.                 if v:IsA("Tool") and v:FindFirstChild("IsBlocking") then
  32.                     local enemyWeapon = v
  33.                     if v then
  34.                         if enemyWeapon:FindFirstChild("IsBlocking").Value == true then
  35.                             if ((enemyWeapon.Handle.Position - t.Position).magnitude) < ((h.Parent.Torso.Position - t.Position).magnitude) then
  36.                                 swinging = false;
  37.                                 local clashSound = Instance.new("Sound", handle) or handle:FindFirstChild("Sound");
  38.                                 clashSound.SoundId = "rbxassetid://"..clashId;
  39.                                 clashSound:Play();
  40.                             elseif ((enemyWeapon.Handle.Position - t.Position).magnitude) > ((h.Parent.Torso.Position - t.Position).magnitude) then
  41.                                 swinging = false;
  42.                                 h:TakeDamage(slashdmg);
  43.                             end;
  44.                         elseif v:FindFirstChild("IsBlocking").Value == false then
  45.                             swinging = false;
  46.                             h:TakeDamage(slashdmg);
  47.                         end;
  48.                     else
  49.                         swinging = false;
  50.                         h:TakeDamage(slashdmg);
  51.                     end;
  52.                 end;
  53.             end;
  54.         end;
  55.     end;
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement