local b={Damage=50;AttackTime=.5;CoolDown=0;LastSwing=0;LastHit=0,Part=nil;Owner=nil;OnHit=nil,OnHitHumanoid=nil;OnAttackReady=nil,OnAttack=nil;SwingSound=nil;HitSound=nil;SwingAnimation=nil;ActiveConnections={}}do UTIL.MakeClass(b)function b.New(W,H)local O=UTIL.DeepCopy(b)O.Part=W O.Owner=H table.insert(O.ActiveConnections,O.Part.Touched:connect(function(b)O:SwordTouch(b)end))O.OnHit=InternalEvent.New()O.OnHitHumanoid=InternalEvent.New()O.OnAttackReady=InternalEvent.New()O.OnAttack=InternalEvent.New()return O end function b.SwordTouch(W,b)if tick()-W.LastSwing>W.AttackTime or tick()-W.LastHit<W.AttackTime then return end W.OnHit:Fire(b)local H,O=UTIL.FindCharacterAncestor(b)if H and H~=W.Owner.Character then remoteEvent:FireServer(O,W.Damage)W.OnHitHumanoid:Fire(O,b)W.LastHit=tick()if W.HitSound then W.HitSound:Play()end end end function b.DoSwing(b)if tick()-b.LastSwing<b.AttackTime+b.CoolDown then return end if b.SwingAnimation then b.SwingAnimation:Play()end if b.SwingSound then b.SwingSound:Play()end b.LastSwing=tick()b.OnAttack:Fire()end function b.Destroy(b)for b,W in pairs(b.ActiveConnections)do W:disconnect()end end end do local W=script.Parent local H=W.Parent local O=game.Players.LocalPlayer local z=UTIL.WaitForValidCharacter(O)local M=(UTIL.Instantiate("\065\110\105\109\097\116\105\111\110"))({AnimationId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\065\115\115\101\116\063\073\068\061\056\057\050\056\057\056\055\057"})local S=W:WaitForChild("\072\105\116")local C=W:WaitForChild("\083\119\105\110\103")local k local U H.Equipped:connect(function(H)U=b.New(W,O)U.Damage=40 U.HitSound=S U.SwingSound=C z=UTIL.WaitForValidCharacter(O)local n=z:FindFirstChild("\072\117\109\097\110\111\105\100")k=n:LoadAnimation(M)U.SwingAnimation=k H.Button1Down:connect(function()U:DoSwing()end)end)H.Unequipped:connect(function()U:Destroy()end)end
--
	
local SwordPart =
{
	Damage = 50,
	AttackTime = 0.5,
	CoolDown = 0,
	
	LastSwing = 0,
	LastHit = 0,

	Part= nil,
	Owner = nil,--player object that owns this sword
	
	OnHit = nil,
	OnHitHumanoid = nil,
	OnAttackReady = nil,
	OnAttack = nil,
	
	
	SwingSound = nil,
	HitSound = nil,
	SwingAnimation = nil, --animation track!
	
	ActiveConnections = {},
	
}
do
	UTIL.MakeClass(SwordPart)
	function SwordPart.New(npart,nowner)
		local init= UTIL.DeepCopy(SwordPart)
		init.Part= npart
		init.Owner = nowner
		table.insert(init.ActiveConnections,init.Part.Touched:connect(function(hit) init:SwordTouch(hit) end))
		
		init.OnHit = InternalEvent.New()
		init.OnHitHumanoid = InternalEvent.New()
		init.OnAttackReady = InternalEvent.New()
		init.OnAttack = InternalEvent.New()
		
		return init
	end
	
	function SwordPart:SwordTouch(hit)
		if tick()-self.LastSwing >self.AttackTime or tick()-self.LastHit<self.AttackTime then return end
		self.OnHit:Fire(hit)
		local character,humanoid = UTIL.FindCharacterAncestor(hit)
		if character and character ~= self.Owner.Character then
			--humanoid:TakeDamage(self.Damage)
			remoteEvent:FireServer(humanoid, self.Damage);
			self.OnHitHumanoid:Fire(humanoid,hit)
			self.LastHit = tick()
			if self.HitSound then
				self.HitSound:Play()
			end
		end
		
	end
	
	function SwordPart:DoSwing()
		if tick()-self.LastSwing<self.AttackTime+self.CoolDown then
			return
		end
		
		if self.SwingAnimation then
			self.SwingAnimation:Play()
		end
		if self.SwingSound then
			self.SwingSound:Play()
		end
		self.LastSwing = tick()
		self.OnAttack:Fire()
	end
	
	function SwordPart:Destroy()
		for _,i in pairs(self.ActiveConnections) do
			i:disconnect()
		end
	end
end
do
	local Handle = script.Parent
	local Tool = Handle.Parent
	
	local Player = game.Players.LocalPlayer
	local Character = UTIL.WaitForValidCharacter(Player)
	local SwingAni = UTIL.Instantiate"Animation"
	{AnimationId = "http://www.roblox.com/Asset?ID=89289879"}
	
	local HitSound = Handle:WaitForChild('Hit')
	local SwingSound = Handle:WaitForChild('Swing')
	
	local SwingAniTrack
	
	local Sword
	
	
	Tool.Equipped:connect(function(mouse)
		Sword = SwordPart.New(Handle,Player)
		Sword.Damage = 40
		Sword.HitSound = HitSound
		Sword.SwingSound = SwingSound
		Character = UTIL.WaitForValidCharacter(Player)
		local Humanoid = Character:FindFirstChild('Humanoid')

		SwingAniTrack = Humanoid:LoadAnimation(SwingAni)
		Sword.SwingAnimation = SwingAniTrack
		
		mouse.Button1Down:connect(function()
			Sword:DoSwing()
		end)
	end)
	Tool.Unequipped:connect(function()
		Sword:Destroy()
	end)

end
