local function g(g,e)while not g:FindFirstChild(e)do g.ChildAdded:wait()end return g[e]end local e=40 local V=70 local y=60 local b=.4 local p=55 local M=nil local E=nil local u=nil local I=nil local B=script.Parent local k=g(B,"\072\097\110\100\108\101")local h local Y local v local Z local n local T local w local R=B.TextureId local X=game:GetService("\068\101\098\114\105\115")local j=game:GetService("\080\108\097\121\101\114\115")local N local s={}local a=nil local f=false function Blow(g)if f then BlowDamage(g,p)end end function BlowDamage(g,e)local V=g.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")local y=j:GetPlayerFromCharacter(g.Parent)if V~=nil and(M~=nil and V~=M)then if not I.Neutral then if y and(y~=I and y.TeamColor==I.TeamColor)then return end end local g=u:FindFirstChild("\082\105\103\104\116 \065\114\109")if g~=nil then local y=g:FindFirstChild("\082\105\103\104\116\071\114\105\112")if y~=nil and(y.Part0==k or y.Part1==k)then TagHumanoid(V,I)print("\083\101\110\100\105\110\103 "..e)local g=V.Parent:findFirstChild("\083\111\117\110\100")if g==nil then local g=script.Parent.Sound:clone()g.Parent=V.Parent g.Disabled=false else g:remove()local e=script.Parent.Sound:clone()e.Parent=V.Parent e.Disabled=false end wait()V:TakeDamage(V.MaxHealth)if V.Health==math.huge or V.MaxHealth==math.huge then V.Parent:BreakJoints()end end end end end function TagHumanoid(g,e)while g:FindFirstChild("\099\114\101\097\116\111\114")do(g:FindFirstChild("\099\114\101\097\116\111\114")):Destroy()end local V=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")V.Value=e V.Name="\099\114\101\097\116\111\114"V.Parent=g X:AddItem(V,1.5)local y=Instance.new("\083\116\114\105\110\103\086\097\108\117\101")y.Value=R y.Name="\105\099\111\110"y.Parent=V X:AddItem(y,1.5)end function HardAttack()p=e HitSound:play()if Z then Z.Value=true wait(1.0)Z.Value=false end end function NormalAttack()p=V KnifeDown()HitSound:play()if n then n.Value=true wait(1.0)n.Value=false end KnifeUp()end function ThrowAttack()KnifeOut()if T then T.Value=true wait()if not k then return end local g=k:Clone()X:AddItem(g,5)g.Parent=game.Workspace if u and M then g.Velocity=(M.TargetPoint-g.CFrame.p).unit*100 g.CFrame=CFrame.new(g.CFrame.p,g.CFrame.p+g.Velocity)*CFrame.Angles(0,0,math.rad(-90))local e=Instance.new("\066\111\100\121\070\111\114\099\101",g)e.force=Vector3.new(0,(196.2*g:GetMass())*.98,0)local V=Instance.new("\066\111\100\121\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121",g)V.angularvelocity=g.CFrame:vectorToWorldSpace(Vector3.new(0,-400,0))end k.Transparency=1 wait()if g then local e=script.Parent.ThrowHandleHitWeld:Clone()e.Parent=g e.Disabled=false local V=g.Touched:connect(function(g)print("\104\105\116 \116\104\114\111\119")BlowDamage(g,y)end)end if g then g.CanCollide=true end wait(.6)if k and T then k.Transparency=0 T.Value=false end end KnifeUp()end function KnifeUp()B.GripForward=Vector3.new(0,0,-1)B.GripRight=Vector3.new(1,0,0)B.GripUp=Vector3.new(0,1,0)end function KnifeDown()B.GripForward=Vector3.new(0,0,-1)B.GripRight=Vector3.new(1,0,0)B.GripUp=Vector3.new(0,-1,0)end function KnifeOut()B.GripForward=Vector3.new(0,0,-1)B.GripRight=Vector3.new(1,0,0)B.GripUp=Vector3.new(0,1,0)end B.Enabled=true function OnLeftButtonDown()a=time()if w then w.Value=true end end function OnLeftButtonUp()if not B.Enabled then return end s={}if w then w.Value=false end if B.Enabled and(M and M.Health>0)then B.Enabled=false local g=time()if a and(g-a>b and g-a<1.15)then ThrowAttack()else f=true if math.random(1,2)==1 then HardAttack()else NormalAttack()end f=false end B.Enabled=true end end function OnEquipped(e)Z=g(B,"\080\108\097\121\083\116\097\098\080\117\110\099\104")n=g(B,"\080\108\097\121\068\111\119\110\083\116\097\098")T=g(B,"\080\108\097\121\084\104\114\111\119")w=g(B,"\080\108\097\121\084\104\114\111\119\067\104\097\114\103\101")N=g(k,"\083\119\111\111\115\104\049")HitSound=g(k,"\084\105\110\103")N:play()h=k.Touched:connect(Blow)u=B.Parent E=u:FindFirstChild("\084\111\114\115\111")M=u:FindFirstChild("\072\117\109\097\110\111\105\100")I=j.LocalPlayer if e then Y=e.Button1Down:connect(OnLeftButtonDown)v=e.Button1Up:connect(OnLeftButtonUp)end KnifeUp()end function OnUnequipped()if h then h:disconnect()h=nil end if Y then Y:disconnect()Y=nil end if v then v:disconnect()v=nil end M=nil end B.Equipped:connect(OnEquipped)B.Unequipped:connect(OnUnequipped)
--------------------- TEMPLATE BLADE WEAPON ---------------------------
-- Waits for the child of the specified parent
local function WaitForChild(parent, childName)
	while not parent:FindFirstChild(childName) do
		parent.ChildAdded:wait()
	end
	return parent[childName]
end

local SLASH_DAMAGE = 40
local DOWNSTAB_DAMAGE = 70
local THROWING_DAMAGE = 60
local HOLD_TO_THROW_TIME = 0.4

local Damage = 55

local MyHumanoid = nil
local MyTorso = nil
local MyCharacter = nil
local MyPlayer = nil

local Tool = script.Parent
local Handle = WaitForChild(Tool, "Handle")

local BlowConnection
local Button1DownConnection
local Button1UpConnection

local PlayStabPunch
local PlayDownStab
local PlayThrow
local PlayThrowCharge

local IconUrl = Tool.TextureId -- URL to the weapon knife icon asset

local DebrisService = game:GetService("Debris")
local PlayersService = game:GetService("Players")

local SlashSound

local HitPlayers = {}

local LeftButtonDownTime = nil

local Attacking = false

function Blow(hit)
	if Attacking then
		BlowDamage(hit, Damage)
	end
end

function BlowDamage(hit, damage)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	local player = PlayersService:GetPlayerFromCharacter(hit.Parent)
	if humanoid ~= nil and MyHumanoid ~= nil and humanoid ~= MyHumanoid then
		if not MyPlayer.Neutral then
			-- Ignore teammates hit
			if player and player ~= MyPlayer and player.TeamColor == MyPlayer.TeamColor then
				return
			end
		end
		-- final check, make sure weapon is in-hand
		local rightArm = MyCharacter:FindFirstChild("Right Arm")
		if rightArm ~= nil then
			-- Check if the weld exists between the hand and the weapon
			local joint = rightArm:FindFirstChild("RightGrip")
			if joint ~= nil and (joint.Part0 == Handle or joint.Part1 == Handle) then
				-- Make sure you only hit them once per swing
				TagHumanoid(humanoid, MyPlayer)
				print("Sending " .. damage)

				local checksound = humanoid.Parent:findFirstChild("Sound")
				if checksound == nil then
					local givesound = script.Parent.Sound:clone()
					givesound.Parent = humanoid.Parent
					givesound.Disabled = false
				else
					checksound:remove()
					local givesound = script.Parent.Sound:clone()
					givesound.Parent = humanoid.Parent
					givesound.Disabled = false
				end
				wait()
				humanoid:TakeDamage(humanoid.MaxHealth)
				if humanoid.Health == math.huge or humanoid.MaxHealth == math.huge then
					humanoid.Parent:BreakJoints()
				end
			end
		end
	end
end

function TagHumanoid(humanoid, player)
	-- Add more tags here to customize what tags are available.
	while humanoid:FindFirstChild("creator") do
		humanoid:FindFirstChild("creator"):Destroy()
	end

	local creatorTag = Instance.new("ObjectValue")
	creatorTag.Value = player
	creatorTag.Name = "creator"
	creatorTag.Parent = humanoid
	DebrisService:AddItem(creatorTag, 1.5)

	local weaponIconTag = Instance.new("StringValue")
	weaponIconTag.Value = IconUrl
	weaponIconTag.Name = "icon"
	weaponIconTag.Parent = creatorTag
	DebrisService:AddItem(weaponIconTag, 1.5)
end

function HardAttack()
	Damage = SLASH_DAMAGE
	HitSound:play()
	if PlayStabPunch then
		PlayStabPunch.Value = true
		wait(1.0)
		PlayStabPunch.Value = false
	end
end

function NormalAttack()
	Damage = DOWNSTAB_DAMAGE
	KnifeDown()
	HitSound:play()
	if PlayDownStab then
		PlayDownStab.Value = true
		wait(1.0)
		PlayDownStab.Value = false
	end
	KnifeUp()
end

function ThrowAttack()
	KnifeOut()
	if PlayThrow then
		PlayThrow.Value = true
		wait()
		if not Handle then
			return
		end
		local throwingHandle = Handle:Clone()
		DebrisService:AddItem(throwingHandle, 5)
		throwingHandle.Parent = game.Workspace
		if MyCharacter and MyHumanoid then
			throwingHandle.Velocity = (MyHumanoid.TargetPoint - throwingHandle.CFrame.p).unit * 100
			-- set the orientation to the direction it is being thrown in
			throwingHandle.CFrame = CFrame.new(
				throwingHandle.CFrame.p,
				throwingHandle.CFrame.p + throwingHandle.Velocity
			) * CFrame.Angles(0, 0, math.rad(-90))
			local floatingForce = Instance.new("BodyForce", throwingHandle)
			floatingForce.force = Vector3.new(0, 196.2 * throwingHandle:GetMass() * 0.98, 0)
			local spin = Instance.new("BodyAngularVelocity", throwingHandle)
			spin.angularvelocity = throwingHandle.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
		end
		Handle.Transparency = 1
		-- Wait so that the knife has left the thrower's general area
		wait()
		if throwingHandle then
			local Throwevent = script.Parent.ThrowHandleHitWeld:Clone()
			Throwevent.Parent = throwingHandle
			Throwevent.Disabled = false
			local touchedConn = throwingHandle.Touched:connect(function(hit)
				print("hit throw")
				BlowDamage(hit, THROWING_DAMAGE)
			end)
		end
		-- must check if it still exists since we waited
		if throwingHandle then
			throwingHandle.CanCollide = true
		end
		wait(0.6)
		if Handle and PlayThrow then
			Handle.Transparency = 0
			PlayThrow.Value = false
		end
	end
	KnifeUp()
end

function KnifeUp()
	Tool.GripForward = Vector3.new(0, 0, -1)
	Tool.GripRight = Vector3.new(1, 0, 0)
	Tool.GripUp = Vector3.new(0, 1, 0)
end

function KnifeDown()
	Tool.GripForward = Vector3.new(0, 0, -1)
	Tool.GripRight = Vector3.new(1, 0, 0)
	Tool.GripUp = Vector3.new(0, -1, 0)
end

function KnifeOut()
	Tool.GripForward = Vector3.new(0, 0, -1)
	Tool.GripRight = Vector3.new(1, 0, 0)
	Tool.GripUp = Vector3.new(0, 1, 0)
end

Tool.Enabled = true

function OnLeftButtonDown()
	LeftButtonDownTime = time()
	if PlayThrowCharge then
		PlayThrowCharge.Value = true
	end
end

function OnLeftButtonUp()
	if not Tool.Enabled then
		return
	end
	-- Reset the list of hit players every time we start a new attack
	HitPlayers = {}
	if PlayThrowCharge then
		PlayThrowCharge.Value = false
	end
	if Tool.Enabled and MyHumanoid and MyHumanoid.Health > 0 then
		Tool.Enabled = false
		local currTime = time()
		if
			LeftButtonDownTime
			and currTime - LeftButtonDownTime > HOLD_TO_THROW_TIME
			and currTime - LeftButtonDownTime < 1.15
		then
			ThrowAttack()
		else
			Attacking = true
			if math.random(1, 2) == 1 then
				HardAttack()
			else
				NormalAttack()
			end
			Attacking = false
		end
		Tool.Enabled = true
	end
end

function OnEquipped(mouse)
	PlayStabPunch = WaitForChild(Tool, "PlayStabPunch")
	PlayDownStab = WaitForChild(Tool, "PlayDownStab")
	PlayThrow = WaitForChild(Tool, "PlayThrow")
	PlayThrowCharge = WaitForChild(Tool, "PlayThrowCharge")
	SlashSound = WaitForChild(Handle, "Swoosh1")
	HitSound = WaitForChild(Handle, "Ting")
	SlashSound:play()
	BlowConnection = Handle.Touched:connect(Blow)
	MyCharacter = Tool.Parent
	MyTorso = MyCharacter:FindFirstChild("Torso")
	MyHumanoid = MyCharacter:FindFirstChild("Humanoid")
	MyPlayer = PlayersService.LocalPlayer
	if mouse then
		Button1DownConnection = mouse.Button1Down:connect(OnLeftButtonDown)
		Button1UpConnection = mouse.Button1Up:connect(OnLeftButtonUp)
	end
	KnifeUp()
end

function OnUnequipped()
	-- Unequip logic here
	if BlowConnection then
		BlowConnection:disconnect()
		BlowConnection = nil
	end
	if Button1DownConnection then
		Button1DownConnection:disconnect()
		Button1DownConnection = nil
	end
	if Button1UpConnection then
		Button1UpConnection:disconnect()
		Button1UpConnection = nil
	end
	MyHumanoid = nil
end

Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)
