local function X()if target then maid.alignOrientation.Enabled=true maid.worldAttachment.CFrame=CFrame.new(maid.humanoidRootPart.Position,target.Position)else maid.alignOrientation.Enabled=false end if not target or not isInstaceAttackable(target)then findTargets()end end local function F()target=nil attacking=false newTarget=nil searchParts=nil searchingForTargets=false maid.heartbeatConnection:Disconnect()if RAGDOLL_ENABLED then Ragdoll(maid.instance,maid.humanoid)end if DESTROY_ON_DEATH then delay(DEATH_DESTROY_DELAY,function()destroy()end)end end


local function onHeartbeat()
	if target then
		-- Point towards the enemy
		maid.alignOrientation.Enabled = true
		maid.worldAttachment.CFrame = CFrame.new(maid.humanoidRootPart.Position, target.Position)
	else
		maid.alignOrientation.Enabled = false
	end

	-- Check if the current target no longer exists or is not attackable
	if not target or not isInstaceAttackable(target) then
		findTargets()
	end
end

local function died()
	target = nil
	attacking = false
	newTarget = nil
	searchParts = nil
	searchingForTargets = false

	maid.heartbeatConnection:Disconnect()

	if RAGDOLL_ENABLED then
		Ragdoll(maid.instance, maid.humanoid)
	end

	if DESTROY_ON_DEATH then
		delay(DEATH_DESTROY_DELAY, function()
			destroy()
		end)
	end
end
