local q={Damage=20;AttackTime=1;CoolDown=2;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(q)function q.New(n,g)local M=UTIL.DeepCopy(q)M.Part=n M.Owner=g table.insert(M.ActiveConnections,M.Part.Touched:connect(function(q)M:SwordTouch(q)end))M.OnHit=InternalEvent.New()M.OnHitHumanoid=InternalEvent.New()M.OnAttackReady=InternalEvent.New()M.OnAttack=InternalEvent.New()return M end function q.SwordTouch(n,q)if tick()-n.LastSwing>n.AttackTime or tick()-n.LastHit<n.AttackTime then return end n.OnHit:Fire(q)local g,M=UTIL.FindCharacterAncestor(q)if g and g~=n.Owner.Character then M:TakeDamage(n.Damage)n.OnHitHumanoid:Fire(M,q)n.LastHit=tick()if n.HitSound then n.HitSound:Play()end end end function q.DoSwing(q)if tick()-q.LastSwing<q.AttackTime+q.CoolDown then return end if q.SwingAnimation then q.SwingAnimation:Play()end if q.SwingSound then q.SwingSound:Play()end q.LastSwing=tick()q.OnAttack:Fire()end function q.Destroy(q)for q,n in pairs(q.ActiveConnections)do n:disconnect()end end end do local n=script.Parent local g=n.Parent local M=game.Players.LocalPlayer local N=UTIL.WaitForValidCharacter(M)local d=(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 x=n:WaitForChild("\072\105\116")local v=n:WaitForChild("\083\119\105\110\103")local P local K g.Equipped:connect(function(g)K=q.New(n,M)K.Damage=40 K.HitSound=x K.SwingSound=v N=UTIL.WaitForValidCharacter(M)local a=N:FindFirstChild("\072\117\109\097\110\111\105\100")P=a:LoadAnimation(d)K.SwingAnimation=P K.OnHitHumanoid:Connect(function(q,g)local M=N:FindFirstChild("\084\111\114\115\111")local d=q.Parent:FindFirstChild("\084\111\114\115\111")if not d or not M then return end if g.Name=="\082\105\103\104\116 \065\114\109"or g.Name=="\076\101\102\116 \065\114\109"or g.Name=="\082\105\103\104\116 \076\101\103"or g.Name=="\076\101\102\116 \076\101\103"then g:BreakJoints()WeldUtil.WeldBetween(g,n)Delay(1,function()g:BreakJoints()end)end end)g.Button1Down:connect(function()K:DoSwing()end)end)g.Unequipped:connect(function()K:Destroy()end)end
--
	
local SwordPart =
{
	Damage = 20,
	AttackTime = 1,
	CoolDown = 2,
	
	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)
			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
		
		Sword.OnHitHumanoid:Connect(function(humanoid,hit)
			local myTorso = Character:FindFirstChild('Torso')
			local torso = humanoid.Parent:FindFirstChild('Torso')
			if not torso or not myTorso then return end
			
			if hit.Name=='Right Arm' or hit.Name=='Left Arm' or hit.Name=='Right Leg' or hit.Name=='Left Leg' then
				hit:BreakJoints()
				WeldUtil.WeldBetween(hit, Handle)
				Delay(1,function() hit:BreakJoints() end )
			end
		end)
		
		mouse.Button1Down:connect(function()
			Sword:DoSwing()
		end)
	end)
	Tool.Unequipped:connect(function()
		Sword:Destroy()
	end)

end
