sp=script.Parent damage=0 damagewindow=1 swingrate=.65 clashsounds={91154405,91154446,91154471;91154503,91154521}swooshsounds={89357340;89357340}hitsounds={91154909,91154932;91154954}anims={"\083\116\097\098\049","\083\116\097\098\050";"\076\101\102\116\083\108\097\115\104"}ready=false equipped=false rate=.033333333333333 lastswing=0 function waitfor(n,t)while n:FindFirstChild(t)==nil do n.ChildAdded:wait()end return n:FindFirstChild(t)end reloading=waitfor(sp,"\082\101\108\111\097\100\105\110\103")down=waitfor(sp,"\077\111\117\115\101\068\111\119\110")runanim=waitfor(sp,"\082\117\110\065\110\105\109")sparkles=waitfor(sp.Handle,"\083\112\097\114\107\108\101\115")debris=game:getService("\068\101\098\114\105\115")weaponhud=waitfor(sp,"\087\101\097\112\111\110\072\117\100")weaponnametag=waitfor(weaponhud,"\087\101\097\112\111\110\078\097\109\101")guibar=waitfor(weaponhud,"\066\097\114")guibarfill=waitfor(guibar,"\070\105\108\108")weaponnametag.Text=sp.Name function runsound(n,t)local H=t or 1 local B=Instance.new("\083\111\117\110\100")B.Looped=false B.Pitch=1 B.SoundId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061"..tostring(n)B.PlayOnRemove=false B.Volume=H debris:AddItem(B,3)B.Parent=sp.Handle wait()B:Play()end function billboard(n,t,H,B)local S=n or Vector3.new(0,0,0)local Z=t or"\072\101\108\108\111 \087\111\114\108\100\033"local I=H or 2 local O=B or Color3.new(1,0,0)local G=S+Vector3.new(0,5,0)local i=Instance.new("\080\097\114\116")i.Name="\069\102\102\101\099\116"i.formFactor="\067\117\115\116\111\109"i.Size=Vector3.new(0,0,0)i.TopSurface="\083\109\111\111\116\104"i.BottomSurface="\083\109\111\111\116\104"i.CFrame=CFrame.new(G)i.Anchored=true i.CanCollide=false i.Transparency=1 local o=Instance.new("\066\105\108\108\098\111\097\114\100\071\117\105")o.Size=UDim2.new(3,0,3,0)o.Adornee=i local k=Instance.new("\084\101\120\116\076\097\098\101\108")k.BackgroundTransparency=1 k.Size=UDim2.new(0,0,0,0)k.Text=Z k.TextColor3=O k.TextScaled=true k.Font="\065\114\105\097\108\066\111\108\100"k.Parent=o o.Parent=i debris:AddItem(i,I+.1)i.Parent=game.Workspace delay(0,function()local n=I/rate for t=1,n,1 do wait(rate)local H=t/n i.CFrame=CFrame.new(G)+Vector3.new(0,5*H,0)k.TextTransparency=H end i:remove()end)end function makeblood(n) end sp.Handle.Touched:connect(function(n)if ready and(equipped and(n and(n.Parent~=nil and(n:IsDescendantOf(sp.Parent)==false and(string.lower(string.sub(n.Name,1,6))~="\101\102\102\101\099\116"and tick()-lastswing<=damagewindow)))))then if n:FindFirstChild("\067\097\110\066\108\111\099\107")and sp.Handle:FindFirstChild("\066\108\111\099\107\097\098\108\101")then ready=false runsound(clashsounds[math.random(1,#clashsounds)])sparkles.Enabled=true delay(.2,function()sparkles.Enabled=false end)billboard(sp.Handle.Position,"\066\108\111\099\107",2,Color3.new(1,1,0))end local t=sp.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")local H=n.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")local B=sp.Parent:FindFirstChild("\082\105\103\104\116 \065\114\109")local S=game.Players:GetPlayerFromCharacter(sp.Parent)if t and(H and(H~=t and(t.Health>0 and(H.Health>0 and(B and S~=nil)))))then if not S.Neutral then local n=game.Players:GetPlayerFromCharacter(H.Parent)if n~=nil and(n.Neutral==false and n.TeamColor==S.TeamColor)then return end end ready=false for n,t in ipairs(H:GetChildren())do if t.Name=="\099\114\101\097\116\111\114"then t:remove()end end local t=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")t.Name="\099\114\101\097\116\111\114"t.Value=S t.Parent=H debris:AddItem(t,1)local B=math.floor(damage*(.9+math.random()*.2))H:TakeDamage(B)billboard(n.Position,"-"..tostring(B))runsound(hitsounds[math.random(1,#hitsounds)])local Z=math.ceil(B/10)for t=1,math.random(Z-1,Z+1),1 do makeblood(n)end end end end)function Activate()if equipped and tick()-lastswing>=swingrate then ready=true reloading.Value=true runsound(swooshsounds[math.random(1,#swooshsounds)],.5)newanim=anims[math.random(1,#anims)]while newanim==runanim.Value do newanim=anims[math.random(1,#anims)]end runanim.Value=newanim lastswing=tick()updategui()wait(swingrate)reloading.Value=false if down.Value then Activate()end end end down.Changed:connect(function()if down.Value then Activate()end end)function updategui()local n=math.min((tick()-lastswing)/swingrate,1)if n<.5 then guibarfill.BackgroundColor3=Color3.new(1,n*2,0)else guibarfill.BackgroundColor3=Color3.new(1-(n-.5)/.5,1,0)end guibarfill.Size=UDim2.new(n,0,1,0)end sp.Equipped:connect(function(n)lastswing=tick()updategui()reloading.Value=true ready=false equipped=true delay(0,function()local n=game.Players:GetPlayerFromCharacter(sp.Parent)if n~=nil then local t=n:FindFirstChild("\080\108\097\121\101\114\071\117\105")if t~=nil and weaponhud~=nil then weaponhud.Parent=t while equipped do updategui()wait(rate)end end end end)wait(swingrate)reloading.Value=false if down.Value then Activate()end end)sp.Unequipped:connect(function()ready=false equipped=false delay(0,function()weaponhud.Parent=sp end)end)



sp=script.Parent


damage=0						--  +/- 10%
damagewindow=1					--after clicking, how long does the player have to hit the opponent wioth their weapon to deal damage
swingrate=.65

clashsounds={91154405,91154446,91154471,91154503,91154521}
swooshsounds={89357340,89357340}
hitsounds={91154909,91154932,91154954}
anims={"Stab1","Stab2","LeftSlash"}



ready=false
equipped=false
rate=1/30
lastswing=0


function waitfor(a,b)
	while a:FindFirstChild(b)==nil do
		a.ChildAdded:wait()
	end
	return a:FindFirstChild(b)
end

reloading=waitfor(sp,"Reloading")
down=waitfor(sp,"MouseDown")
runanim=waitfor(sp,"RunAnim")
sparkles=waitfor(sp.Handle,"Sparkles")
debris=game:getService("Debris")
weaponhud=waitfor(sp,"WeaponHud")
weaponnametag=waitfor(weaponhud,"WeaponName")
guibar=waitfor(weaponhud,"Bar")
guibarfill=waitfor(guibar,"Fill")
weaponnametag.Text=sp.Name

function runsound(id,volume)
	local volume=volume or 1
	local sound=Instance.new("Sound")
	sound.Looped=false
	sound.Pitch=1
	sound.SoundId="http://www.roblox.com/asset/?id="..tostring(id)
	sound.PlayOnRemove=false
	sound.Volume=volume
	debris:AddItem(sound,3)
	sound.Parent=sp.Handle
	wait()
	sound:Play()
end

function billboard(pos,text,time,color)
	local pos=pos or Vector3.new(0,0,0)
	local text=text or "Hello World!"
	local time=time or 2
	local color=color or Color3.new(1,0,0)
	local pos=pos+Vector3.new(0,5,0)
	local ep=Instance.new("Part")
	ep.Name="Effect"
	ep.formFactor="Custom"
	ep.Size=Vector3.new(0,0,0)
	ep.TopSurface="Smooth"
	ep.BottomSurface="Smooth"
	ep.CFrame=CFrame.new(pos)
	ep.Anchored=true
	ep.CanCollide=false
	ep.Transparency=1
	local bb=Instance.new("BillboardGui")
	bb.Size=UDim2.new(3,0,3,0)
	bb.Adornee=ep
	local tl=Instance.new("TextLabel")
	tl.BackgroundTransparency=1
	tl.Size=UDim2.new(0,0,0,0)
	tl.Text=text
	tl.TextColor3=color
	tl.TextScaled=true
	tl.Font="ArialBold"

	tl.Parent=bb
	bb.Parent=ep
	debris:AddItem(ep,time+.1)
	ep.Parent=game.Workspace
	delay(0,function()
		local frames=time/rate
		for frame=1,frames do
			wait(rate)
			local percent=frame/frames
			ep.CFrame=CFrame.new(pos)+Vector3.new(0,5*percent,0)
			tl.TextTransparency=percent
		end
		ep:remove()
	end)
end

function makeblood(part)
	--[[
	if part then
		local b=Instance.new("Part")
		b.BrickColor=BrickColor.new("Bright red")
		b.formFactor="Custom"
		b.Transparency=math.random(0,1)*.5
		if math.random()<.5 then
			b.CanCollide=false
		else
			b.CanCollide=true
		end
		b.TopSurface="Smooth"
		b.BottomSurface="Smooth"
		b.Size=Vector3.new(.2*math.random(1,5),.2*math.random(1,5),.2*math.random(1,5))
		b.Velocity=part.Velocity+(Vector3.new((math.random()-.5),(math.random()-.5),(math.random()-.5))*30)
		b.RotVelocity=part.RotVelocity+(Vector3.new((math.random()-.5),(math.random()-.5),(math.random()-.5))*20)
		b.CFrame=part.CFrame*CFrame.new((math.random()-.5)*3,(math.random()-.5)*3,(math.random()-.5)*3)*CFrame.Angles(math.pi*2*math.random(),math.pi*2*math.random(),math.pi*2*math.random())
		debris:AddItem(b,math.random()*4)
		b.Parent=game.Workspace
	end
	--]]
end

sp.Handle.Touched:connect(function(hit)
	if ready and equipped and hit and hit.Parent~=nil and hit:IsDescendantOf(sp.Parent)==false and string.lower(string.sub(hit.Name,1,6))~="effect" and (tick()-lastswing)<=damagewindow then
		if hit:FindFirstChild("CanBlock") and sp.Handle:FindFirstChild("Blockable") then
			ready=false
			runsound(clashsounds[math.random(1,#clashsounds)])
			sparkles.Enabled=true
			delay(.2,function()
				sparkles.Enabled=false
			end)
			billboard(sp.Handle.Position,"Block",2,Color3.new(1,1,0))
		end
		local mh=sp.Parent:FindFirstChild("Humanoid")
		local eh=hit.Parent:FindFirstChild("Humanoid")
		local ra=sp.Parent:FindFirstChild("Right Arm")
		local plr=game.Players:GetPlayerFromCharacter(sp.Parent)
		if mh and eh and eh~=mh and mh.Health>0 and eh.Health>0 and ra and plr~=nil then
			if not plr.Neutral then
				local eplr=game.Players:GetPlayerFromCharacter(eh.Parent)
				if eplr~=nil and eplr.Neutral==false and eplr.TeamColor==plr.TeamColor then
					return	--No team killing
				end
			end
			ready=false
			for i,v in ipairs(eh:GetChildren()) do
				if v.Name=="creator" then
					v:remove()
				end
			end
			local creator=Instance.new("ObjectValue")
			creator.Name="creator"
			creator.Value=plr
			creator.Parent=eh
			debris:AddItem(creator,1)
			local localdamage=math.floor(damage*(.9+(math.random()*.2)))
			eh:TakeDamage(localdamage)
			billboard(hit.Position,"-"..tostring(localdamage))
			runsound(hitsounds[math.random(1,#hitsounds)])
			local bloodeffects=math.ceil(localdamage/10)
			for i=1,math.random(bloodeffects-1,bloodeffects+1) do
				--[[if math.random()<.5 then
					makeblood(sp.Handle)
				else]]
					makeblood(hit)
				--end
			end
		end
	end
end)


function Activate()
	if equipped and (tick()-lastswing)>=swingrate then
		ready=true
		reloading.Value=true

		runsound(swooshsounds[math.random(1,#swooshsounds)],.5)

		newanim=anims[math.random(1,#anims)]
		while newanim==runanim.Value do
			newanim=anims[math.random(1,#anims)]
		end
		runanim.Value=newanim

		lastswing=tick()
		updategui()

		wait(swingrate)

		reloading.Value=false
		if down.Value then
			Activate()
		end
	end
end

down.Changed:connect(function()
	if down.Value then
		Activate()
	end
end)

function updategui()
	local swingpercent=math.min((tick()-lastswing)/swingrate,1)
	if swingpercent<.5 then	--fade from red to yellow then to green
		guibarfill.BackgroundColor3=Color3.new(1,swingpercent*2,0)
	else
		guibarfill.BackgroundColor3=Color3.new(1-((swingpercent-.5)/.5),1,0)
	end
	guibarfill.Size=UDim2.new(swingpercent,0,1,0)
end

sp.Equipped:connect(function(mouse)
	lastswing=tick()
	updategui()

	reloading.Value=true
	ready=false
	equipped=true

	delay(0,function()		--HAAB (Hacking around a bug)
		local plr=game.Players:GetPlayerFromCharacter(sp.Parent)
		if plr~=nil then
			local plrgui=plr:FindFirstChild("PlayerGui")
			if plrgui~=nil and weaponhud~=nil then
				weaponhud.Parent=plrgui
				while equipped do
					updategui()
					wait(rate)
				end
			end
		end
	end)

	wait(swingrate)

	reloading.Value=false
	if down.Value then
		Activate()
	end
end)

sp.Unequipped:connect(function()
	ready=false
	equipped=false
	delay(0,function()	--HAAB
		weaponhud.Parent=sp
	end)
end)







