local function D(D,V)while not D:FindFirstChild(V)do D.ChildAdded:wait()end return D[V]end local V=150 local x=150 local k=150 local u=.38 local W=100 local r=nil local g=nil local b=nil local i=nil local v=script.Parent local T=D(v,"\072\097\110\100\108\101")local B local f local O local J local a local o local l local y=v.TextureId local d=Game:GetService("\068\101\098\114\105\115")local w=Game:GetService("\080\108\097\121\101\114\115")local A local m={}local G=nil local R=false function Blow(D)if R then BlowDamage(D,W)end end function BlowDamage(D,V)local x=D.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")local k=w:GetPlayerFromCharacter(D.Parent)if x==nil then T.WallHit:Play()wait(.1)if game.Workspace.Handle==nil then else game.Workspace.Handle:Destroy()end else if x.Health==0 then else(T.Ragdoll:clone()).Parent=D.Parent x.Health=0 T.DeadPlayer:Play()T.DeadSound:Play()end wait(.1)if game.Workspace.Handle==nil then else game.Workspace.Handle:Destroy()end end if x~=nil and(r~=nil and x~=r)then if not i.Neutral then if k and(k~=i and k.TeamColor==i.TeamColor)then return end end local D=b:FindFirstChild("\082\105\103\104\116 \065\114\109")if D~=nil then local u=D:FindFirstChild("\082\105\103\104\116\071\114\105\112")if u~=nil and(u.Part0==T or u.Part1==T)then if k and not m[k]then TagHumanoid(x,i)print("\083\101\110\100\105\110\103 "..V)x:TakeDamage(V)T.Splat.Volume=1 T.Splat:Play()m[k]=true end end end end end function TagHumanoid(D,V)while D:FindFirstChild("\099\114\101\097\116\111\114")do(D:FindFirstChild("\099\114\101\097\116\111\114")):Destroy()end local x=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")x.Value=V x.Name="\099\114\101\097\116\111\114"x.Parent=D d:AddItem(x,1.5)local k=Instance.new("\083\116\114\105\110\103\086\097\108\117\101")k.Value=y k.Name="\105\099\111\110"k.Parent=x d:AddItem(k,1.5)end function HardAttack()T.Attack:Play()if J then J.Value=true wait(1.0)J.Value=false end end function NormalAttack()W=x KnifeDown()T.Attack:Play()if a then a.Value=true wait(1.0)a.Value=false end KnifeUp()end function ThrowAttack()KnifeOut()if o then o.Value=true wait(.3)if not T then return end local D=T:Clone()d:AddItem(D,5)D.Parent=Workspace T.Throw:Play()if b and r then D.Velocity=(r.TargetPoint-D.CFrame.p).unit*300 D.CFrame=CFrame.new(D.CFrame.p,D.CFrame.p+D.Velocity)*CFrame.Angles(0,0,math.rad(-90))local V=Instance.new("\066\111\100\121\070\111\114\099\101",D)V.force=Vector3.new(0,(196.2*D:GetMass())*.98,0)local x=Instance.new("\066\111\100\121\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121",D)x.angularvelocity=D.CFrame:vectorToWorldSpace(Vector3.new(0,-400,0))end T.Transparency=1 wait(.08)if D then local V=D.Touched:connect(function(D)print("\104\105\116 \116\104\114\111\119")BlowDamage(D,k)end)end if D then D.CanCollide=true end wait(.6)if T and o then T.Transparency=0 o.Value=false end end KnifeUp()end function KnifeUp()v.GripForward=Vector3.new(0,0,-1)v.GripRight=Vector3.new(1,0,0)v.GripUp=Vector3.new(0,1,0)end function KnifeDown()v.GripForward=Vector3.new(0,0,-1)v.GripRight=Vector3.new(1,0,0)v.GripUp=Vector3.new(0,-1,0)end function KnifeOut()v.GripForward=Vector3.new(0,0,-1)v.GripRight=Vector3.new(1,0,0)v.GripUp=Vector3.new(0,1,0)end v.Enabled=true function OnLeftButtonDown()G=time()end function OnLeftButtonUp()if not v.Enabled then return end m={}if l then l.Value=false end if v.Enabled and(r and r.Health>0)then v.Enabled=false local D=time()if G and(D-G>u and D-G<1.15)then else R=true if math.random(1,2)==1 then HardAttack()else NormalAttack()end R=false end v.Enabled=true end end function OnRightButtonDown()RightButtonDownTime=time()if l then l.Value=true end end function OnRightButtonUp()if not v.Enabled then return end m={}if l then l.Value=false end if v.Enabled and(r and r.Health>0)then v.Enabled=false local D=time()if RightButtonDownTime and(D-RightButtonDownTime>u and D-RightButtonDownTime<1.15)then ThrowAttack()else R=true if math.random(1,2)==1 then else end R=false end v.Enabled=true end end function OnEquipped(V)J=D(v,"\080\108\097\121\083\116\097\098\080\117\110\099\104")a=D(v,"\080\108\097\121\068\111\119\110\083\116\097\098")o=D(v,"\080\108\097\121\084\104\114\111\119")l=D(v,"\080\108\097\121\084\104\114\111\119\067\104\097\114\103\101")T.Equip:Play()B=T.Touched:connect(Blow)b=v.Parent g=b:FindFirstChild("\084\111\114\115\111")r=b:FindFirstChild("\072\117\109\097\110\111\105\100")i=w.LocalPlayer if V then f=V.Button1Down:connect(OnLeftButtonDown)O=V.Button1Up:connect(OnLeftButtonUp)Button2DownConnection=V.Button2Down:connect(OnRightButtonDown)Button2UpConnection=V.Button2Up:connect(OnRightButtonUp)end KnifeUp()end function OnUnequipped()if B then B:disconnect()B=nil end if f then f:disconnect()f=nil end if O then O:disconnect()O=nil end if Button2UpConnection then Button2UpConnection:disconnect()Button2UpConnection=nil end if Button2DownConnection then Button2DownConnection:disconnect()Button2DownConnection=nil end r=nil end v.Equipped:connect(OnEquipped)v.Unequipped:connect(OnUnequipped)

local function WaitForChild(parent, childName)
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end


local SLASH_DAMAGE = 150
local DOWNSTAB_DAMAGE = 150
local THROWING_DAMAGE = 150
local HOLD_TO_THROW_TIME = 0.38


local Damage = 100

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 then
		Handle.WallHit:Play()
		wait(0.1)
		if game.Workspace.Handle == nil then
		else
			game.Workspace.Handle:Destroy()
		end
	else
		if humanoid.Health == 0 then
		else
			Handle.Ragdoll:clone().Parent = hit.Parent
			humanoid.Health = 0
			Handle.DeadPlayer:Play()
			Handle.DeadSound:Play()
		end
		wait(0.1)
		if game.Workspace.Handle == nil then
		else
			game.Workspace.Handle:Destroy()
		end
	end
	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
				if player and not HitPlayers[player] then
					TagHumanoid(humanoid, MyPlayer)
					print("Sending " .. damage)
					humanoid:TakeDamage(damage)
					Handle.Splat.Volume = 1
					Handle.Splat:Play()
					HitPlayers[player] = true
				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()
	Handle.Attack:Play()
	if PlayStabPunch then
		PlayStabPunch.Value = true
		wait(1.0)
		PlayStabPunch.Value = false
	end
end

function NormalAttack()
	Damage = DOWNSTAB_DAMAGE
	KnifeDown()
	Handle.Attack: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(0.3)
		if not Handle then return end
		local throwingHandle = Handle:Clone()
		DebrisService:AddItem(throwingHandle, 5)
		throwingHandle.Parent = Workspace
		Handle.Throw:Play()
		if MyCharacter and MyHumanoid then
			throwingHandle.Velocity = (MyHumanoid.TargetPoint - throwingHandle.CFrame.p).unit * 300
			-- 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(0.08)
		if throwingHandle then
			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()
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
		else
			Attacking = true
			if math.random(1, 2) == 1 then
				HardAttack()
			else
				NormalAttack()
			end
			Attacking = false
		end
		Tool.Enabled = true
	end
end

function OnRightButtonDown()
	RightButtonDownTime = time()
    if PlayThrowCharge then
		PlayThrowCharge.Value = true
	end
end

function OnRightButtonUp()
		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 RightButtonDownTime and currTime - RightButtonDownTime > HOLD_TO_THROW_TIME and
			currTime - RightButtonDownTime < 1.15 then
			ThrowAttack()
		else
			Attacking = true
			if math.random(1, 2) == 1 then
			else
			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')
Handle.Equip: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)
		Button2DownConnection = mouse.Button2Down:connect(OnRightButtonDown)
		Button2UpConnection = mouse.Button2Up:connect(OnRightButtonUp)
	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
	if Button2UpConnection then
		Button2UpConnection:disconnect()
		Button2UpConnection = nil
	end
	if Button2DownConnection then
		Button2DownConnection:disconnect()
		Button2DownConnection = nil
	end
	MyHumanoid = nil
end


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